Catch instance/fetch error, only set instance_fetch_failed on 404

This commit is contained in:
Alex Gleason
2022-05-02 11:46:18 -05:00
parent 4e01e93da5
commit 0fa58be38c
2 changed files with 13 additions and 6 deletions

View File

@@ -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;
},
);