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
Bug using Error in the return data strucutre of a promise.
While there is no error raise, the toast take the error branch with the following message HTTP error! status: undefined
Steps to reproduce the bug 馃攣:
promise data structure return
export type Result<T, E = Error> =
| { ok: true; value: T }
| { ok: false; error: E };
export function Ok<T, E>(value: T): Result<T, E> {
return { ok: true, value };
}
export function Err<T, E>(error: E): Result<T, E> {
return { ok: false, error };
}
There is a miss understanding. The library infer that all data structure with .ok and .error is a http request: problem here
LatentDream
changed the title
Bug using Error in the return data strucutre
Bug: falsy infer a http request when there is ok and Error in the return data strucutre
Mar 4, 2024
We catch errors in our backend and return a structured response with an error key to indicate an error. It'd be great to be able to escape hatch by throwing an error and propagating the specific message to the error toast.
toast.promise(response,{loading: messages.saveLoading,success: (response)=>{if('errorKey'inresponse){consterrorMessage=getTranslatedError(response.errorKey,lang);thrownewError(errorMessage??messages.fallbackErrorMessage);}else{returnselectedEntity===''
? messages.successRemovedDescription
: messages.successDescription;}},// catch error and deconstruct the messageerror: (e)=>e.message??messages.fallbackErrorMessage});
Edit: just did a little more digging, pretty easy to achieve this if anyone else stumbles here by using the id returned by the loading toast:
constid=toast.loading(messages.saveLoading);constresponse=awaitrequest(request,configLocator,lang);if('errorKey'inresponse){consterrorMessage=getTranslatedError(response.errorKey,lang);toast.error(errorMessage??messages.fallbackErrorMessage,{ id });}else{toast.success(selectedEntity===''
? messages.successRemovedDescription
: messages.successDescription,{ id },);}
Describe the feature / bug 馃摑:
Bug using Error in the return data strucutre of a promise.
While there is no error raise, the toast take the error branch with the following message
HTTP error! status: undefined
Steps to reproduce the bug 馃攣:
promise data structure return
Code to reproduce the bug
This return:
Error Raise: HTTP error! status: undefined
The text was updated successfully, but these errors were encountered: