DEV Community

Discussion on: Central Error Handling in Express

Collapse
 
mr_cea profile image
Ogbonna Basil • Edited

This is cool,

Just one opinion, i feel it should be expanded to be not just Error Handler but statusHandler

```
class statusHandler extends Error {
constructor(statusCode, message, data) {
super();
this.statusCode = statusCode;
this.message = message;
this.data = data || null

}
}
module.exports = {
statusHandler
}




Likewise for handleError but generally this approach is effectively DRY. Nice one
Collapse
 
nedsoft profile image
Chinedu Orie

Just like Express is unopinionated, how you apply the concept in the article is also unopinionated. And except I do not understand you clearly, it'd not make sense semantically to throw a success response as an error. Thanks for sharing your views.