You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed in the main Controller of the bundle, in case of JSON syntax error, a RuntimeException in thrown, which result to a 500 HTTP return code by Symfony with an "Internal Server Error" HTML response.
thrownew \RuntimeException('Invalid JSON received in POST body: '.json_last_error_msg());
}
if (!is_array($parsedBody)){
thrownew \RuntimeException('Expecting associative array from request, got ' . gettype($parsedBody));
}
In my point of view, both cases should return a JSON response formatted as GraphQL response with errors, with a 400 HTTP code like :
{
"errors": [
{
"message": "Invalid JSON received in POST body",
"extensions": {
"reason": "Syntax error"
}
}
]
}
or
{
"errors": [
{
"message": "Invalid JSON received in POST body",
"extensions": {
"reason": "Expecting associative array from request, got string"
}
}
]
}
The trick is that we are outside of the GraphQL Server context, so throwing a GraphQLException here doesn't have the desired effect. But the solution could be to create an GraphQLException Listener then create a JsonResponse from an ExecutionResult+Error from the GraphQLException.
What do you think ?
Already tried it so I can work on it and submit a PR.
The text was updated successfully, but these errors were encountered:
I totaly agree with you, it's would be very more clear (and usefull to monitor the error log).
But for error code I suggest to use 415 (Unsupported Media Type) if it's not parsable json, or 422 (Unprocessable Entity) if the json is not associative.
Hi,
I've noticed in the main Controller of the bundle, in case of JSON syntax error, a RuntimeException in thrown, which result to a 500 HTTP return code by Symfony with an "Internal Server Error" HTML response.
graphqlite-bundle/Controller/GraphQLiteController.php
Lines 84 to 89 in 9fc3c79
In my point of view, both cases should return a JSON response formatted as GraphQL response with errors, with a 400 HTTP code like :
or
The trick is that we are outside of the GraphQL Server context, so throwing a GraphQLException here doesn't have the desired effect. But the solution could be to create an GraphQLException Listener then create a JsonResponse from an ExecutionResult+Error from the GraphQLException.
What do you think ?
Already tried it so I can work on it and submit a PR.
The text was updated successfully, but these errors were encountered: