Skip to content

Commit

Permalink
refactor: update error handler i18n message identifier and JSONAPI er…
Browse files Browse the repository at this point in the history
…ror code
  • Loading branch information
thetutlage committed Jan 22, 2024
1 parent 676338d commit 4d3ec8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AuthorizationException extends Exception {
/**
* Error identifier to lookup translation message
*/
identifier = 'access.denied'
identifier = 'errors.E_AUTHORIZATION_FAILURE'

constructor(
public response: AuthorizationResponse,
Expand Down Expand Up @@ -86,7 +86,7 @@ class AuthorizationException extends Exception {
ctx.response.status(status).send({
errors: [
{
code: this.identifier,
code: this.code,
title: message,
},
],
Expand Down
6 changes: 3 additions & 3 deletions tests/authorization_exception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test.group('AuthorizationException', () => {
async load() {
return {
en: {
'access.denied': 'Access denied from translations',
'errors.E_AUTHORIZATION_FAILURE': 'Access denied from translations',
},
}
},
Expand Down Expand Up @@ -74,7 +74,7 @@ test.group('AuthorizationException', () => {
async load() {
return {
en: {
'access.denied': 'Access denied from translations',
'errors.E_AUTHORIZATION_FAILURE': 'Access denied from translations',
'errors.not_found': 'Page not found',
},
}
Expand Down Expand Up @@ -116,7 +116,7 @@ test.group('AuthorizationException', () => {

await exception.handle(exception, ctx)
assert.deepEqual(ctx.response.getBody(), {
errors: [{ code: 'access.denied', title: 'Access denied' }],
errors: [{ code: 'E_AUTHORIZATION_FAILURE', title: 'Access denied' }],
})
assert.equal(ctx.response.getStatus(), 403)
})
Expand Down

0 comments on commit 4d3ec8b

Please sign in to comment.