aboutsummaryrefslogtreecommitdiff
path: root/src/services/errors/errors.js
diff options
context:
space:
mode:
authorHJ <30-hj@users.noreply.git.pleroma.social>2019-08-06 18:03:32 +0000
committerHJ <30-hj@users.noreply.git.pleroma.social>2019-08-06 18:03:32 +0000
commit17dc7357d5036681b346f745190204e213c0ef8c (patch)
tree33966f59ce8dbf4f75afb43bbb24ec860ff98aaf /src/services/errors/errors.js
parent0e6489d84019ac146af1dd5df9f1db548b4df5ac (diff)
parent4fc27414d25d719991d2368740c5ffea67af907d (diff)
Merge branch 'issue-617' into 'develop'
Handle JSONified errors while registering Closes #617 See merge request pleroma/pleroma-fe!888
Diffstat (limited to 'src/services/errors/errors.js')
-rw-r--r--src/services/errors/errors.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/services/errors/errors.js b/src/services/errors/errors.js
index 548f3c68..590552da 100644
--- a/src/services/errors/errors.js
+++ b/src/services/errors/errors.js
@@ -1,3 +1,5 @@
+import { humanizeErrors } from '../../modules/errors'
+
export function StatusCodeError (statusCode, body, options, response) {
this.name = 'StatusCodeError'
this.statusCode = statusCode
@@ -12,3 +14,36 @@ export function StatusCodeError (statusCode, body, options, response) {
}
StatusCodeError.prototype = Object.create(Error.prototype)
StatusCodeError.prototype.constructor = StatusCodeError
+
+export class RegistrationError extends Error {
+ constructor (error) {
+ super()
+ if (Error.captureStackTrace) {
+ Error.captureStackTrace(this)
+ }
+
+ try {
+ // the error is probably a JSON object with a single key, "errors", whose value is another JSON object containing the real errors
+ if (typeof error === 'string') {
+ error = JSON.parse(error)
+ if (error.hasOwnProperty('error')) {
+ error = JSON.parse(error.error)
+ }
+ }
+
+ if (typeof error === 'object') {
+ // replace ap_id with username
+ if (error.ap_id) {
+ error.username = error.ap_id
+ delete error.ap_id
+ }
+ this.message = humanizeErrors(error)
+ } else {
+ this.message = error
+ }
+ } catch (e) {
+ // can't parse it, so just treat it like a string
+ this.message = error
+ }
+ }
+}