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
In the project code, there's no way of knowing the specific error of the API request, as only message, status and statusText ara available.
Proposal
I think it would be nice that it accepts more data, so there's more context about the error when handling it. Potential use cases:
returning zod issues when validating in the BE, that could be retrieved on the FE to map those errors to form fields
returning field more data for certain exceptions, such as duplicated data, to know which field is the one that triggered the error
The simplest implementation would be to pass the original response instance to the error so it can be accessed in the error handler. This would prevent the client to take any part of extracting the payload, it would be deferred to the handler.
Example
Example of implementation (code in Medusa SDK)
update FetchError to accept extra parameter in constructor
consthandleSubmit=form.handleSubmit(async(values)=>{awaitentityCreateMutation.mutateAsync({body: values,}).then(({ data })=>{toast.success("Entity created successfully");returnhandleSuccess(`/entities/${data.handle}`);}).catch(async(error: FetchError)=>{toast.error("Failed to create entity");awaitsetFetchErrorsInForm(form,error?.response);});});
potential mapping of errors from API response to form errors (example implementation, not fully tested):
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Context
Currently
FetchError
is thrown for non success HTTP statuses, but little information is provided alongside it. See:medusa/packages/core/js-sdk/src/client.ts
Line 84 in 4ea1a2e
In the project code, there's no way of knowing the specific error of the API request, as only
message
,status
andstatusText
ara available.Proposal
I think it would be nice that it accepts more data, so there's more context about the error when handling it. Potential use cases:
The simplest implementation would be to pass the original response instance to the error so it can be accessed in the error handler. This would prevent the client to take any part of extracting the payload, it would be deferred to the handler.
Example
Example of implementation (code in Medusa SDK)
FetchError
to accept extra parameter in constructorExample of usage (code in Medusa projects)
Discussion topics
MedusaError
so it could be also accessible in the FE?Beta Was this translation helpful? Give feedback.
All reactions