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,34 +148,24 @@ describe('fetchAccountByUsername()', () => {
|
|||
const username = 'tiger';
|
||||
let state, account;
|
||||
|
||||
describe('when the account has already been cached in redux', () => {
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({
|
||||
id,
|
||||
acct: username,
|
||||
display_name: 'Tiger',
|
||||
avatar: 'test.jpg',
|
||||
birthday: undefined,
|
||||
});
|
||||
|
||||
state = rootReducer(undefined, {})
|
||||
.set('accounts', ImmutableMap({
|
||||
[id]: account,
|
||||
}));
|
||||
|
||||
store = mockStore(state);
|
||||
|
||||
__stub((mock) => {
|
||||
mock.onGet(`/api/v1/accounts/${id}`).reply(200, account);
|
||||
});
|
||||
beforeEach(() => {
|
||||
account = normalizeAccount({
|
||||
id,
|
||||
acct: username,
|
||||
display_name: 'Tiger',
|
||||
avatar: 'test.jpg',
|
||||
birthday: undefined,
|
||||
});
|
||||
|
||||
it('should return null', async() => {
|
||||
const result = await store.dispatch(fetchAccountByUsername(username));
|
||||
const actions = store.getActions();
|
||||
state = rootReducer(undefined, {})
|
||||
.set('accounts', ImmutableMap({
|
||||
[id]: account,
|
||||
}));
|
||||
|
||||
expect(actions).toEqual([]);
|
||||
expect(result).toBeNull();
|
||||
store = mockStore(state);
|
||||
|
||||
__stub((mock) => {
|
||||
mock.onGet(`/api/v1/accounts/${id}`).reply(200, account);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
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