Skip to content

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 requested review from StormFireFox1 and steets250 May 31, 2022 00:50
@yesean yesean self-assigned this May 31, 2022

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.

3 participants