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

Fix error handling #571

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix error handling #571

wants to merge 1 commit into from

Conversation

yesean
Copy link
Contributor

@yesean yesean commented May 31, 2022

This PR adds UserError and AuthError types to differentiate between server errors. In the redux cleaning, I was dispatching logout on all server errors but now I only dispatch logout on AuthError.

In the future, I think there should be a more unified way of handling UserError as generally, we just notify with an error message which can be abstracted. I've already created this kind of abstraction in src/auth/authSlice.ts in the withLogout HOF which takes an async function f and returns an async thunk that dispatches a logout when f throws an AuthError. I think a similar HOF could be created for UserError which sends a notify if a UserError is thrown. If such a withNotify HOF is created, then withLogout would probably have to be modified to allow for error chaining before creating the async thunk.

Differentiate between auth errors and user errors. Only dispatch logouts
on auth errors.
@yesean yesean added the PR: Needs Review This PR needs review label May 31, 2022
@yesean yesean self-assigned this May 31, 2022
@@ -187,9 +188,9 @@ export const fetchService = async (url: string, requestMethod: HttpRequestMethod
});

const { status } = response;
if (status === 401 || status === 403) onFailCallback?.();
if (status === 401 || status === 403) throw new AuthError('');
Copy link
Member

Choose a reason for hiding this comment

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

Would it be doable to add some kind of message in here for the AuthError? I figure maybe the error field of the response might return something useful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Needs Review This PR needs review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants