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.ts
file:
import type { Integration } from "@vue-storefront/middleware";
import type { MiddlewareConfig } from "@vsf-enterprise/sapcc-api";
export default {
integrations: {
sapcc: {
location: '@vsf-enterprise/sapcc-api/server',
errorHandler: (
error
req,
res,
) => {
res.status(404);
res.send('Custom not-found error handler');
},
configuration: { ... },
...
// remaining configuration
} satisfies Integration<MiddlewareConfig>
}
}
Custom error handlers are configured per integration, so you can have different error handlers for different integrations.