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',
useSofa({
schema,
errorHandler(errs) {
logErrors(errors);
return new Response(formatError(errs[0]), {
status: 500,
headers: { 'Content-Type': 'application/json' },
});
},
})
);