zoubingwu / msw-auto-mock

A cli tool to generate random mock data from OpenAPI definition for msw.
246 stars 54 forks source link

TypeError: Failed to construct 'Response': Response with null body status cannot have body #23

Closed HunterECampbell closed 1 year ago

HunterECampbell commented 1 year ago

I have a DELETE endpoint that returns a success status code of 204. I've been getting a "null body" error and have tried using try catch and if else to catch the error, but they aren't working. Removing ctx.json(null) for 204 codes fixes the problem. Here's the error I've been getting with my DELETE 204:

createRequestListener.ts:56 Uncaught (in promise) TypeError: Failed to construct 'Response': Response with null body status cannot have body
    at Object.onMockedResponse (createRequestListener.ts:56:38)
    at handleRequest (handleRequest.ts:127:3)
    at async createRequestListener.ts:34:7
HunterECampbell commented 1 year ago

I created a PR fix for this issue. #22

jamesandersonwalsh commented 1 year ago

I've been experiencing this same issue, would love to see see this issue resolved.

zoubingwu commented 1 year ago

Thanks! Pull request is merged and package released in v0.12.0