-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve (or remove) global error mapping #26
Comments
The simplest approach would be to just use One idea @idg10 and I came up with was to introduce a new attribute for operations, something like this:
This would give us a few nice things:
|
I think this is a good approach, except I'd argue that we shouldn't drop the global exception handling approach at the same time. Sensible global conventions are useful - aiding productivity, and enabling the "pit of success" (eg. ASP.NET MVC routing). Allowing global mapping conventions to be configured centrally, as well as individual cases and exceptions to be configured through attributes provides the best of both worlds. So - the change in mindset would be to move away from global mappings as the default approach, and instead use attribute based mappings. But, in scenarios where global mappings make sense, then they can still be used. |
As part of Menes initialisation, we provide the ability to globally map exceptions to specific response codes. Client libraries can write code like this:
config.Exceptions.Map<TenantNotFoundException>(404);
as part of the initialisation callback.
Whilst this is useful in reducing boilerplate exception handling code in operation methods, it is at heart a sprinkling of magic pixie dust that is not visible from the code that's doing the actual work, and that you have to know is there to understand the full set of potential behaviours of your code.
The corollary to this is that a developer that's unaware of the mapping could add code that invalidates the assumption made in the mapping - i.e. that the specified exception always maps to the given status code.
It would be good to revisit this and see if we can find a better balance between discoverability and the elimination of boilerplate exception handling in client code.
The text was updated successfully, but these errors were encountered: