Error handling
See original GitHub issueThis issue is to keep track of the discussion about to handle errors internally. Main discussions were had in a pull request here and here.
Currently the errors thrown store a status code internally so the ResponseWriter knows which status code to return in the case of an error. The advantage is that this allows for easily adding new errors in the future. The disadvantage is that this makes some of the classes less independent and mixes some reponsabilities. For example, this makes it more difficult to have CompositeAsyncHandler
as a separate package. Not that this is necessary but it might be an indication that there is an issue with this.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
What is Exception Handling? - SearchSoftwareQuality
Exception handling is the process of responding to unwanted or unexpected events when a computer program runs. Exception handling deals with these events...
Read more >Exception handling - Wikipedia
In computing and computer programming, exception handling is the process of responding to the occurrence of exceptions – anomalous or exceptional conditions ...
Read more >Error Handling — The Swift Programming Language (Swift 5.7)
Error handling is the process of responding to and recovering from error conditions in your program. Swift provides first-class support for throwing, ...
Read more >Control flow and error handling - JavaScript - MDN Web Docs
Exception handling statements. You can throw exceptions using the throw statement and handle them using the try...catch statements.
Read more >Error handling - Express.js
Error Handling refers to how Express catches and processes errors that occur both synchronously and asynchronously. Express comes with a default error ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A factory is a definitely viable avenue indeed; it does feel a bit heavy to always have this injected (given how common errors are).
That would make me lean towards a more adapter-like solution, where (for instance) the back-end layer throws a simple “Not Found” / “Not Exists” error, which is a data object that is later translated into the right HTTP error. So basically, factory strategy, but the factory takes in data objects such that not all classes need this factory.
That would then have to be a dependency for most classes though.
The other option is going to non-Http errors as was already suggested before and have a handler somewhere at the end that converts them to status codes (probably called by the responseWriter). And if new errors are introduced they would require also making a new handler for them (which can be combined in a CompositeHandler as usual then).
Both of these do make #23 a bit harder to solve I think 😄