Merge branch 'instance-fetch-fix' into 'develop'
Catch instance/fetch error, only set instance_fetch_failed on 404 See merge request soapbox-pub/soapbox-fe!1296
This commit is contained in:
commit
9fc79c942e
2 changed files with 13 additions and 6 deletions
|
@ -39,12 +39,16 @@ const needsNodeinfo = (instance: Record<string, any>): boolean => {
|
||||||
|
|
||||||
export const fetchInstance = createAsyncThunk<void, void, { state: RootState }>(
|
export const fetchInstance = createAsyncThunk<void, void, { state: RootState }>(
|
||||||
'instance/fetch',
|
'instance/fetch',
|
||||||
async(_arg, { dispatch, getState }) => {
|
async(_arg, { dispatch, getState, rejectWithValue }) => {
|
||||||
|
try {
|
||||||
const { data: instance } = await api(getState).get('/api/v1/instance');
|
const { data: instance } = await api(getState).get('/api/v1/instance');
|
||||||
if (needsNodeinfo(instance)) {
|
if (needsNodeinfo(instance)) {
|
||||||
dispatch(fetchNodeinfo());
|
dispatch(fetchNodeinfo());
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
|
} catch(e) {
|
||||||
|
return rejectWithValue(e);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,10 @@ const ReducerRecord = ImmutableRecord({
|
||||||
export default function meta(state = ReducerRecord(), action: AnyAction) {
|
export default function meta(state = ReducerRecord(), action: AnyAction) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case fetchInstance.rejected.type:
|
case fetchInstance.rejected.type:
|
||||||
|
if (action.payload.response?.status === 404) {
|
||||||
return state.set('instance_fetch_failed', true);
|
return state.set('instance_fetch_failed', true);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue