Open jonchurch opened 1 year ago
Locate the typescript-fetch
generator's source: Investigate the generator's source code to understand the error handling mechanism and identify potential customizations to align with the pure Fetch behavior.
Update the OpenAPI SpaceTraders spec: To include the necessary error types, extend the OpenAPI spec with relevant error definitions, providing better support for typed error objects.
Improve error response handling: Modify the generator's runtime to handle error responses more intuitively. This may involve ensuring that response.json()
is called for both successful and unsuccessful responses.
Update documentation: Once the error handling mechanism is improved, update the package documentation to provide clear guidance on how to handle errors, with examples showcasing the updated behavior.
Test the updated error handling behavior: Execute comprehensive tests to ensure that the improved error handling meets the desired behavior and does not introduce any unexpected side effects.
Part of this is thinking about if it's just worth switching to Axios. It's trivial to swap out the http client for the generator.
This project is a toy and an exercise in Not Invented Here, as is the whole spacetraders game for me. So using native Fetch in Node 18 and writing code to enrich it's experience without installing deps is fun. But, the openapi generator has already made some choices for us in terms of enriching fetch, and those were NIH. So let's not cling too dearly to the idea of writing a bunch of custom stuff unless it provides value.
Axios handles a lot of this stuff very well, but I'm trying to find a balance between having fun working with new tools (Node Native Fetch) and creating a useful library for myself and others.
Handling Errors in @spacejunk/airlock
This issue is for tracking a few concerns related to error handling in the
@spacejunk/airlock
package while using Fetch as the http client:typescript-fetch
generator throws aResponseError
for status codes above 299, which is a departure from the pure Fetch behavior. This choice is not intentional but is imposed by the generator's source, which still needs to be located.response.json()
. The generator's runtime handlesresponse.json()
for successful requests, so it's unexpected for users to have this magic removed for error responses.Here's sample TypeScript code to illustrate the error handling: