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
Use typed responses instead of generic Response type from fetch.
Currently, every component parses the body by itself (including error handling).
With this change applied, calling api endpoints should be much more streamlined and simplified.
asyncfunctionrequest<T>(path: string,config: RequestInit): Promise<T>{constresponse=awaitfetch(newRequest(path,config))if(!response.ok){// TODO: use Api.Helper here instead generic ErrorthrownewError({name: response.status,message: response.statusText})}// may error if there is no body, return emptyreturnresponse.json().catch(()=>({}))}
The text was updated successfully, but these errors were encountered:
Use typed responses instead of generic
Response
type fromfetch
.Currently, every component parses the body by itself (including error handling).
With this change applied, calling api endpoints should be much more streamlined and simplified.
e.g. from https://eckertalex.dev/blog/typescript-fetch-wrapper
The text was updated successfully, but these errors were encountered: