You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
The text was updated successfully, but these errors were encountered:
artdent
changed the title
useFetch should reject with an Error object
useFetch should reject with an Error object
Sep 16, 2019
I agree, this should be an Error, not a Response object. However we do want to keep a reference to the failed Response, so I think we need to introduce a FetchError that inherits from Error and has an additional response property.
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:((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).
The text was updated successfully, but these errors were encountered: