Closed
Description
Right now, if there's a request error, parseResponse from useFetch
rejects with the response object instead of with an Error object. This causes two difficulties:
- rejecting with a non-Error means you don't have a full stack trace
- it contradicts the AsyncState type, so if you try to use state.error in TypeScript you have to cast it through unknown, i.e.
((error as unknown) as Response)
. (The intermediate step is necessary because Error and Response are unrelated types.)
The best fix is probably to change useFetch to throw an Error object that has a handle to the underlying response, which is unfortunately a backward-incompatible change. The other possibility I can think of is to widen or parameterize the error type, but I'm not sure it's a good idea to make the signature more complicated to support something that's not a great practice (i.e. throwing non-errors).
Metadata
Metadata
Assignees
Labels
No labels