Handle JSONified errors while registering

Closes #617
This commit is contained in:
Lee Starnes 2019-08-06 18:03:31 +00:00 committed by HJ
parent 0e6489d840
commit 4fc27414d2
3 changed files with 40 additions and 15 deletions

View file

@ -1,7 +1,7 @@
import { each, map, concat, last } from 'lodash'
import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js'
import 'whatwg-fetch'
import { StatusCodeError } from '../errors/errors'
import { RegistrationError, StatusCodeError } from '../errors/errors'
/* eslint-env browser */
const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json'
@ -199,12 +199,11 @@ const register = ({ params, credentials }) => {
...rest
})
})
.then((response) => [response.ok, response])
.then(([ok, response]) => {
if (ok) {
.then((response) => {
if (response.ok) {
return response.json()
} else {
return response.json().then((error) => { throw new Error(error) })
return response.json().then((error) => { throw new RegistrationError(error) })
}
})
}