is there a way how to run an exception through the apollo exception handler manually?
I have 90% of the application in GraphQL but still have two modules as REST and I'd like to unify the way the exceptions are handled.
So the GQL queries throw the standard 200 with errors array containing message, extensions etc.
{
"errors": [
{
"message": { "statusCode": 401, "error": "Unauthorized" },
"locations": [{ "line": 2, "column": 3 }],
"path": [ "users" ],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"response": { "statusCode": 401, "error": "Unauthorized" },
"status": 401,
"message": { "statusCode": 401, "error": "Unauthorized" }
}
}
}
],
"data": null
}
where the REST throws the real 401 with JSON:
{
"statusCode": 401,
"error": "Unauthorized"
}
So can I simply catch and wrap the exception in the Apollo Server format or do I have to format my REST errors manually? Thanks
I am using NestJS and the GraphQL module.