-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add message for FeatureUnavailableException #3402
Changes from 1 commit
f3c2f29
a9025d8
8f76c70
4cfebd9
328b0c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,11 @@ public override void OnException(ExceptionContext context) | |
errorMessage = "Resource not found."; | ||
context.HttpContext.Response.StatusCode = 404; | ||
} | ||
else if (exception is FeatureUnavailableException) | ||
{ | ||
errorMessage = "This feature is not available."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎨 If you want a custom message you can just put this in the exception class below -- set its This handler is to override messages, results, etc. for exceptions we don't own. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure this is right - we own NotFoundException, for example, and many others in this The message given to the constructor will still be included in the error response if it's running in dev mode: https://github.com/bitwarden/server/blob/feature-unavailable-exception-improvements/src/Api/Utilities/ExceptionHandlerFilterAttribute.cs#L133-L141. But this provides a guaranteed user-appropriate message for production use. This does suggest that these properties should just be on the custom Exception object though; this long I am unsure how far to go in this PR in refactoring this class, or what direction it even needs to go in. (Part of a larger problem where we routinely throw in the service layer for control flow.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The status code will still be set. |
||
context.HttpContext.Response.StatusCode = 404; | ||
} | ||
else if (exception is SecurityTokenValidationException) | ||
{ | ||
errorMessage = "Invalid token."; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ The current state of this PR has
FeatureUnavailableException
unused.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still used in
CollectionsController
andCollectionAuthorizationHandler
. We've used those as guards at the top of feature-flagged methods, e.g.That is maybe overkill and misuse of the exception. What do you think? Maybe we should just remove this use of it and rely on unit testing instead, then we don't need the exception at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If your approach to set the result is working well I think it's best to use it everywhere and drop any inconsistent usages.