Merge branch 'lookup-401' into 'develop'
Redirect to /login if viewing an account 401's See merge request soapbox-pub/soapbox-fe!1509
This commit is contained in:
commit
bd95c9f7e8
4 changed files with 19 additions and 26 deletions
|
@ -148,7 +148,6 @@ describe('fetchAccountByUsername()', () => {
|
|||
const username = 'tiger';
|
||||
let state, account;
|
||||
|
||||
describe('when the account has already been cached in redux', () => {
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({
|
||||
id,
|
||||
|
@ -170,15 +169,6 @@ describe('fetchAccountByUsername()', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should return null', async() => {
|
||||
const result = await store.dispatch(fetchAccountByUsername(username));
|
||||
const actions = store.getActions();
|
||||
|
||||
expect(actions).toEqual([]);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when "accountByUsername" feature is enabled', () => {
|
||||
beforeEach(() => {
|
||||
const state = rootReducer(undefined, {})
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -12,9 +12,12 @@ const isRememberFailType = (type: string): boolean => type.endsWith('_REMEMBER_F
|
|||
/** Whether the error contains an Axios response. */
|
||||
const hasResponse = (error: any): boolean => Boolean(error && error.response);
|
||||
|
||||
/** Don't show 401's. */
|
||||
const authorized = (error: any): boolean => error?.response?.status !== 401;
|
||||
|
||||
/** Whether the error should be shown to the user. */
|
||||
const shouldShowError = ({ type, skipAlert, error }: AnyAction): boolean => {
|
||||
return !skipAlert && hasResponse(error) && isFailType(type) && !isRememberFailType(type);
|
||||
return !skipAlert && hasResponse(error) && authorized(error) && isFailType(type) && !isRememberFailType(type);
|
||||
};
|
||||
|
||||
/** Middleware to display Redux errors to the user. */
|
||||
|
|
Loading…
Reference in a new issue