Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma-fe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pleroma
pleroma-fe
Commits
17dc7357
Commit
17dc7357
authored
5 years ago
by
HJ
Browse files
Options
Downloads
Plain Diff
Merge branch 'issue-617' into 'develop'
Handle JSONified errors while registering Closes
#617
See merge request
!888
parents
0e6489d8
4fc27414
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!1028
`master` refresh with `develop`
,
!888
Handle JSONified errors while registering
Pipeline
#15627
passed
5 years ago
Stage: lint
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/modules/users.js
+1
-10
1 addition, 10 deletions
src/modules/users.js
src/services/api/api.service.js
+4
-5
4 additions, 5 deletions
src/services/api/api.service.js
src/services/errors/errors.js
+35
-0
35 additions, 0 deletions
src/services/errors/errors.js
with
40 additions
and
15 deletions
src/modules/users.js
+
1
−
10
View file @
17dc7357
...
...
@@ -3,7 +3,6 @@ import oauthApi from '../services/new_api/oauth.js'
import
{
compact
,
map
,
each
,
merge
,
last
,
concat
,
uniq
}
from
'
lodash
'
import
{
set
}
from
'
vue
'
import
{
registerPushNotifications
,
unregisterPushNotifications
}
from
'
../services/push/push.js
'
import
{
humanizeErrors
}
from
'
./errors
'
// TODO: Unify with mergeOrAdd in statuses.js
export
const
mergeOrAdd
=
(
arr
,
obj
,
item
)
=>
{
...
...
@@ -382,16 +381,8 @@ const users = {
store
.
dispatch
(
'
loginUser
'
,
data
.
access_token
)
}
catch
(
e
)
{
let
errors
=
e
.
message
// replace ap_id with username
if
(
typeof
errors
===
'
object
'
)
{
if
(
errors
.
ap_id
)
{
errors
.
username
=
errors
.
ap_id
delete
errors
.
ap_id
}
errors
=
humanizeErrors
(
errors
)
}
store
.
commit
(
'
signUpFailure
'
,
errors
)
throw
Error
(
errors
)
throw
e
}
},
async
getCaptcha
(
store
)
{
...
...
This diff is collapsed.
Click to expand it.
src/services/api/api.service.js
+
4
−
5
View file @
17dc7357
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
Registration
Error
(
error
)
})
}
})
}
...
...
This diff is collapsed.
Click to expand it.
src/services/errors/errors.js
+
35
−
0
View file @
17dc7357
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
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment