micronaut-projects / micronaut-graphql

A repository for Micronaut and GraphQL integrations
Apache License 2.0
80 stars 43 forks source link

Sending malformed Query request results in HTTP 500 instead of HTTP 400 #555

Open chetansj27 opened 1 week ago

chetansj27 commented 1 week ago

Expected Behavior

Server should respond with HTTP 400 to malformed requests. image Instead of RuntimeException if we can throw JsonParseException then it will be easy to handle that error in GlobalErrorHandler because RuntimeException is very generic and if we handle RuntimeException then it will handle other exceptions also.

Actual Behaviour

Unexpected error occurred: Error deserializing object from JSON: Unexpected character ('q' (code 113)): was expecting double-quote to start field name at [Source: (byte[]) with 500 error.

Steps To Reproduce

To Reproduce:

  1. Setup a server with any GraphQL schema.
  2. Send POST request to the server with request body set to "Bad request" or any other invalid Json.
  3. See HTTP 500 error instead of HTTP 400.

Environment Information

OS: Windows Request sent from Postman micronaut-graphql version=4.1.4

Example Application

No response

Version

4.1.4

graemerocher commented 1 week ago

Would you be willing tot send a PR?

chetansj27 commented 1 week ago

Yes, I will be happy to raise PR. Will raise PR by EOD