hasura / hasura/graphql-engine
204 status code from API caused Unexpected end of JSON input error.
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Component
c/v3-engine
### What is the current behaviour?
I'm using OpenAPI connector which successfully interospects swagger-json schema. As the result, for DELETE rest API i have graphql mutation command which will delete some resource from server. In case of successfully deletion REST API returns 204 status code (Means no content in response body at all).
Hasura graphql engine failes with error when tries to parse response from this command.
### What is the expected behaviour?
Hasura should not try to parse any data in case of 204 status code. 200/204 OK should be returned
### How to reproduce the issue?
1. Setup rest api which will return 204 status code
2. Setup hasura openapi ddn connector
3. Using hasura console, Execute mutation. -> 500 internal error will be received, but at the same time the resource will be deleted successfully.
### Screenshots or Screencast
### Please provide any traces or logs that could help here.
Stacktrace:
{"level":50,"time":1762510773066,"pid":19,"hostname":"b7ab1e8701ab","err":{"type":"InternalServerError","message":"Error encountered when invoking function 'DeleteResourceFunction'","stack":"Error: Error encountered when invoking function 'DeleteResourceFunction'\n at invokeFunction (/functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:184:13)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async executeMutationOperation (/functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:96:18)\n at async executeMutation (/functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:69:18)\n at async Object.mutation (/functions/node_modules/@hasura/ndc-lambda-sdk/src/connector.ts:67:14)\n at async Object. (/functions/node_modules/@hasura/ndc-sdk-typescript/src/server.ts:252:32)","statusCode":500,"details":{"type":"Object","message":"Unexpected end of JSON input","stack":"SyntaxError: Unexpected end of JSON input\n at JSON.parse ()\n at parseJSONFromBytes (node:internal/deps/undici/undici:5738:19)\n at successSteps (node:internal/deps/undici/undici:5719:27)\n at consumeBody (node:internal/deps/undici/undici:5725:9)\n at _Response.json (node:internal/deps/undici/undici:5665:18)\n at /functions/api.ts:1021:41\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async DeleteResourceFunction (/functions/functions.ts:910:18)\n at async /functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:176:16\n at async invokeFunction (/functions/node_modules/@hasura/ndc-lambda-sdk/src/execution.ts:172:12)\n"}},"msg":"Error encountered when invoking function 'DeleteResourceFunction'"}
### Keywords
204 status code
No-Content
Unexpected end of JSON input
Contributor guide
Research direction
Start at /functions/api.ts:1021, where the stack trace shows the empty 204 response being parsed, and trace how DELETE mutations invoke that function. Confirm the behavior with an OpenAPI connector returning 204 and consider the issue done when the mutation succeeds without attempting to parse a response body.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100