Error Handling
By default, Sofa returns a response that includes JSON representation of thrown error object from GraphQL with HTTP status code 500. But, you can enhance error handler by adding your errorHandler
function.
api.use(
'/api',
sofa({
schema,
errorHandler(res, errors) {
logErrors(errors);
res.code(500);
res.json(formatError(errors[0]));
},
})
);