-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I provide a custom error boundary for my entry app's entry point (/app) and child routes (app/foo, app/foo/baz)? #597
Comments
Hey! I hear you, error boundaries are tricky right now - we're looking at ways to improve them, but for now we need to do that. We need that error boundary to be in
All that aside, if you just want to add some custom code when errors happen, you can do this: export const ErrorBoundary = () => {
const error = useRouteError();
try {
// Catch redirect Response thrown by @shopify/shopify-app-remix
const shopifyError = boundary.error(error);
return shopifyError;
} catch {
// Run your own code here
return <p>Something went wrong ☹️</p>;
}
}; We'll see if we can add some documentation on how to add your own boundaries, but it will basically be the above :) Hope this helps! |
We are closing this issue because we did not hear back regarding additional details we needed to resolve this issue. If the issue persists and you are able to provide the missing clarification we need, you can respond here or create a new issue. We appreciate your understanding as we try to manage our number of open issues. |
@paulomarg What is the recommended to process to throw a 404 response from a loader, as per the Remix docs? https://remix.run/docs/hi/main/guides/not-found#how-to-send-a-404 |
From what I can tell so far, this works for returning a custom error UI when a 4xx response is thrown. export function ErrorBoundary() {
const error = useRouteError();
if (isRouteErrorResponse(error)) {
return (
<div>
<h1>
{error.status} {error.statusText}
</h1>
<p>{error.data}</p>
</div>
);
} else {
try {
// Catch redirect Response thrown by @shopify/shopify-app-remix
const shopifyError = boundary.error(error);
return shopifyError;
} catch {
// Run your own code here
return <p>Something went wrong ☹️</p>;
}
}
} However it seems like it might contradict what is mentioned above:
@paulomarg can you please clarify if my example above is acceptable for retaining the required ErrorBoundary functionality? |
shopify-app-template-remix/app/routes/app.tsx
Lines 32 to 35 in b796328
This is very confusing for me and I haven't gotten around to understand can I also return a component in my routes that also don't mess up what you guys intend the error boundary to do, which is to use that boundary import from shopify.
I went here in the docs but I left even more confused. I did not grasp how to do it and there's no examples.
I'm asking because currently without error boundaries my app just brakes whenever I have an error server-side and I have to restart my local server every time.
If someone could explain me like I'm 5 haha, would be great, thanks !
The text was updated successfully, but these errors were encountered: