Skip to content

Commit

Permalink
docs: add configurable error handler documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mirouse committed Jul 17, 2023
1 parent 2f0dd3a commit 275a026
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/docs/architecture/server-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,23 @@ export default {
+ }
}
```
## Customize the error handler

The Server Middleware comes with a default error handler that logs errors to the console and sends a generic error response to the client. You can customize this behavior by providing your own error handler function in the `middleware.config.js` file:

```javascript
module.exports = {
integrations: {
ct: {
location: '@vsf-enterprise/commercetools-api/server',
// Express req and res objects
errorHandler: (error: unknown, req: Request, res: Response) => {
res.status(404);
res.send('Custom not-found error handler');
},
configuration: { ... },
...
// remaining configuration
```
Custom error handler are configured per integration, so you can have different error handlers for different integrations.

0 comments on commit 275a026

Please sign in to comment.