GraphQL: Improve session token error messages (#5753)
* GraphQL: Improve session token error message Fixes the session token related error messages during GraphQL operations. If any authentication error were thrown, it was not correctly handled by the GraphQL express middleware, and ended responding the request with a JSON parsing error. * Refactor handleError usage * Use handleParseErrors middleware to handle invalid session token error * fix: Status code 400 when session token is invalid * fix: Undo handleParseErrors middleware change
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
1c62ab6f49
commit
f91034ab8c
14
src/GraphQL/parseGraphQLUtils.js
Normal file
14
src/GraphQL/parseGraphQLUtils.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import Parse from 'parse/node';
|
||||
import { ApolloError } from 'apollo-server-core';
|
||||
|
||||
export function toGraphQLError(error) {
|
||||
let code, message;
|
||||
if (error instanceof Parse.Error) {
|
||||
code = error.code;
|
||||
message = error.message;
|
||||
} else {
|
||||
code = Parse.Error.INTERNAL_SERVER_ERROR;
|
||||
message = 'Internal server error';
|
||||
}
|
||||
return new ApolloError(message, code);
|
||||
}
|
||||
Reference in New Issue
Block a user