Skip to content

Commit

Permalink
feat: add error handler for services
Browse files Browse the repository at this point in the history
  • Loading branch information
Achalhii committed May 15, 2024
1 parent 8fbd53b commit 8090791
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class CampsiService {
this.config = config;
this.options = config.options;
this.router = Router();
this.errorHandler = (err, req, res, next) => {
req.campsi.logger.error(err, `[${this.constructor.name}] ${err.message}`);
next(err);
};
return this;
}

Expand All @@ -38,6 +42,7 @@ class CampsiService {
* @returns {Promise} Return a promise, resolved when service initialization is done
*/
initialize() {
this.router.use(this.errorHandler);
return new Promise(resolve => resolve());
}

Expand Down

0 comments on commit 8090791

Please sign in to comment.