Catch instance/fetch error, only set instance_fetch_failed on 404

api-accept
Alex Gleason 2022-05-02 11:46:18 -05:00
rodzic 4e01e93da5
commit 0fa58be38c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 13 dodań i 6 usunięć

Wyświetl plik

@ -39,12 +39,16 @@ const needsNodeinfo = (instance: Record<string, any>): boolean => {
export const fetchInstance = createAsyncThunk<void, void, { state: RootState }>(
'instance/fetch',
async(_arg, { dispatch, getState }) => {
const { data: instance } = await api(getState).get('/api/v1/instance');
if (needsNodeinfo(instance)) {
dispatch(fetchNodeinfo());
async(_arg, { dispatch, getState, rejectWithValue }) => {
try {
const { data: instance } = await api(getState).get('/api/v1/instance');
if (needsNodeinfo(instance)) {
dispatch(fetchNodeinfo());
}
return instance;
} catch(e) {
return rejectWithValue(e);
}
return instance;
},
);

Wyświetl plik

@ -13,7 +13,10 @@ const ReducerRecord = ImmutableRecord({
export default function meta(state = ReducerRecord(), action: AnyAction) {
switch(action.type) {
case fetchInstance.rejected.type:
return state.set('instance_fetch_failed', true);
if (action.payload.response?.status === 404) {
return state.set('instance_fetch_failed', true);
}
return state;
default:
return state;
}