One of the recommended patterns in the OpenAPI 3.0 specification is the use of default responses when the underlying API returns the same shape of data for a variety of error cases.
Right now, msw-auto-mock generates code with ctx.status(NaN) which is invalid and throws an error like RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599]..
I'm not sure how we can reliably generate the correct mocked responses for cases such as these, since they do not really capture information about which specific errors are expected to be returned from those handlers.
At the very least a note in the README about this edge case would be good for those deciding whether this library will satisfy their specific use case.
Alternatively:
we could assume default responses correspond with a specific status code, like 5XX
we could allow users to specify a list of status codes to generate responses for when we encounter a default response (e.g. defaultStatuses: [404, 500] or something like that)
we could fail more gracefully, by emitting an error during generation if we try to parse a status code and end up with NaN
One of the recommended patterns in the OpenAPI 3.0 specification is the use of
default
responses when the underlying API returns the same shape of data for a variety of error cases.https://swagger.io/docs/specification/describing-responses/#:~:text=each%20response%20individually.-,Default%20Response,-Sometimes%2C%20an%20operation
Right now,
msw-auto-mock
generates code withctx.status(NaN)
which is invalid and throws an error likeRangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599].
.I'm not sure how we can reliably generate the correct mocked responses for cases such as these, since they do not really capture information about which specific errors are expected to be returned from those handlers.
At the very least a note in the README about this edge case would be good for those deciding whether this library will satisfy their specific use case.
Alternatively:
default
responses correspond with a specific status code, like5XX
default
response (e.g.defaultStatuses: [404, 500]
or something like that)NaN