freeCodeCamp / open-api

freeCodeCamp's open-api Intiative
BSD 3-Clause "New" or "Revised" License
89 stars 28 forks source link

Handle invalid JSON #175

Closed ojongerius closed 5 years ago

ojongerius commented 6 years ago

In AWS I see a 502 with "Internal Server error".

Logs show Unexpected token _ in JSON at position 1

Reproduce:

▶ curl -XPOST -H 'Content-Type:application/graphql'  -d '{__schema { queryType { name, fields { name, description} }}}' https://hxtsoafqna.execute-api.us-east-1.amazonaws.com/stage/graphql
{"message": "Internal server error"}%

I guess we need to validate the payload before we continue.

Related: #174

user512 commented 5 years ago

👋 @ojongerius, I took a look at this issue, I was wondering if it's a good idea to check valid JSON or empty body inside this try block? https://github.com/freeCodeCamp/open-api/blob/dc7f111078b905a1a8d5fd9a4574c715a7c3e5b6/src/handler.js#L60-L68