Skip to content
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

feat: add error boundary #319

Merged
merged 1 commit into from
Oct 25, 2024
Merged

Conversation

tylerslaton
Copy link
Contributor

This adds an error boundary for the _auth routes. By adding this, errors are handled in a more consistent manner in a way that is interactable for the user.

In addition this removes the sonners that would be shown when API errors occurred. If they are blocking errors, the user will now be directed to the error boundary. We'll want things to be more specific in the future, but this is a great start.

Screen.Recording.2024-10-24.at.10.21.42.PM.mov

This adds an error boundary for the _auth routes.
By adding this, errors are handled in a more consistent
manner in a way that is interactable for the user.

In addition this removes the sonners that would be
shown when API errors occurred. If they are blocking
errors, the user will now be directed to the error
boundary. We'll want things to be more specific
in the future, but this is a great start.

Signed-off-by: tylerslaton <[email protected]>
Copy link
Contributor

@ryanhopperlowe ryanhopperlowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple things to clean up regarding window.href, but other than that looks great!

<Button
className="w-full"
variant="secondary"
onClick={() => window.location.reload()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be using the useNavigate hook to perform routing options. It will handle some other stuff that Remix needs to manage it's router

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you recommend using useNavigate here? I tried a couple of things but nothing worked quite like this. I Know it reloads the whole page but that was desired by me.

className="w-full"
variant="secondary"
onClick={() => {
window.location.href =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. The useNavigate hook is preferred over setting the window.location

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional since the Remix router will route to this with /admin prefixed. We do not want this here.

Comment on lines +14 to +27
switch (true) {
case error instanceof AxiosError:
if (
error.response?.status === 403 &&
me.username &&
me.username !== AuthDisabledUsername
) {
return <Unauthorized />;
}
return <SignIn />;
case isRouteErrorResponse(error):
return <RouteError error={error} />;
default:
return <Error error={error as Error} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know this was possible with JS switches 😮

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah classic switch(true)!

variant="secondary"
className="w-full"
onClick={() => {
window.location.href = "/oauth2/start?rd=/admin/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above ^ intentional since it won't work with navigate or link.

@tylerslaton tylerslaton merged commit 43a4329 into obot-platform:main Oct 25, 2024
1 check passed
@tylerslaton tylerslaton deleted the fix-auth-edges branch October 25, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants