Skip to content

Commit

Permalink
feat: improve error message for wrong auth format
Browse files Browse the repository at this point in the history
  • Loading branch information
dbartholomae committed Feb 15, 2019
1 parent 2ce5db7 commit 7f40831
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ describe('JWTAuthMiddleware', () => {
next
)
).rejects.toEqual(
createHttpError(401, 'Format is Authorization: Bearer [token]', {
type: 'WrongAuthFormat'
})
createHttpError(
401,
'Format should be "Authorization: Bearer [token]", received "Authorization: Malformed header" instead',
{
type: 'WrongAuthFormat'
}
)
)
})

Expand Down
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ export class JWTAuthMiddleware {
event.headers.Authorization
}" but should be of format "Bearer token"`
)
throw createHttpError(401, 'Format is Authorization: Bearer [token]', {
type: 'WrongAuthFormat'
})
throw createHttpError(
401,
`Format should be "Authorization: Bearer [token]", received "Authorization: ${
event.headers.Authorization
}" instead`,
{
type: 'WrongAuthFormat'
}
)
}
this.logger('Authorization header formed correctly')

Expand Down

0 comments on commit 7f40831

Please sign in to comment.