-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Non-401 Error Codes from the validateFunc #245
Comments
In the code and tests, the module is fairly explicit about what it's trying to do when it sees a non-unauthorized error: Lines 374 to 414 in fa728d7
That means that we'd need to treat this as a breaking change, most likely. Since the original error is preserved on the error's server.ext({
type: 'onPreResponse',
method: (request, h) => {
const error = request.response;
if (Boom.isBoom(error) && error.output.statusCode === 401 && error.data instanceof Error) {
// Preserve original error from Boom.unauthorized()
return error.data;
}
return h.continue;
}
}); |
Okay, that makes sense, I can definitely see this being suited as a breaking change since it does change a substantial amount of the existing behaviour. Thanks for the snippet! It seems like a suitable stand-in for how I'm wanting the erroring to behave. I think this could be a nice thing to include in a future major-version release, but I am also satisfied with this resolution if this isn't something that is desired within the API. |
Support plan
Context
v14.17.0
11.0.2
20.2.1
)What problem are you trying to solve?
I have a system that involves multiple different "regions" of authorization, I want a cookie to only be valid for one of these "regions", and I have added validation checks into the
validateFunc
. I would love be able to respond to the client with a403 Forbidden
when the cookie provided is for a different "region" than that which it is trying to access.Example:
I have "regions"
1
and2
, and an authorization cookie is used for region1
, but the user is making a request toGET /region/2
I would like to be able tothrow boom.forbidden()
, and it set the response code to403
instead of the plugin only throwing401
to the user.Do you have a new or modified API suggestion to solve the problem?
I think a solution following a similar vein as to how
@hapi/basic
does it where if thevalidateFunc
throws an error(/Boom error) it replaces the defaultboom.unauthorized()
From the
@hapi/basic
API documentation for thevalidate
function:The text was updated successfully, but these errors were encountered: