Skip to content

Commit 08a8c24

Browse files
committed
fix error handling
1 parent 793272b commit 08a8c24

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async function handleKeycloakValidation (tkn, h) {
121121
await cache.set(store, tkn, userData, expiresIn)
122122
return h.authenticated(userData)
123123
} catch (err) {
124-
throw raiseUnauthorized(err, errorMessages.invalid, err.message)
124+
throw raiseUnauthorized(errorMessages.invalid, err.message)
125125
}
126126
}
127127

@@ -143,7 +143,7 @@ async function validate (field, h = (data) => data) {
143143
const reply = fakeToolkit(h)
144144

145145
if (!tkn) {
146-
throw raiseUnauthorized(null, errorMessages.missing)
146+
throw raiseUnauthorized(errorMessages.missing)
147147
}
148148

149149
const cached = await cache.get(store, tkn)

src/utils.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,16 @@ function verify (opts) {
111111
* message. Otherwise the provided message.
112112
*
113113
* @param {Error|null|undefined} err The error object
114-
* @param {string} msg The error message
114+
* @param {string} message The error message
115+
* @param {string} reason The reason for the thrown error
115116
* @param {string} [scheme = 'Bearer'] The related scheme
116117
* @returns {Boom.unauthorized} The created `Boom` error
117118
*/
118-
function raiseUnauthorized (err, msg, reason, scheme = 'Bearer') {
119-
return boom.unauthorized(err ? err.message : msg, scheme, {
119+
function raiseUnauthorized (error, reason, scheme = 'Bearer') {
120+
return boom.unauthorized(null, scheme, {
120121
strategy: 'keycloak-jwt',
121-
...(reason && !err ? { reason } : {})
122+
...(error ? { error } : {}),
123+
...(reason && error !== reason ? { reason } : {})
122124
})
123125
}
124126

0 commit comments

Comments
 (0)