From 0fa58be38c0080cdd59ea96caa42557bc0cb0e61 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 2 May 2022 11:46:18 -0500 Subject: [PATCH] Catch instance/fetch error, only set instance_fetch_failed on 404 --- app/soapbox/actions/instance.ts | 14 +++++++++----- app/soapbox/reducers/meta.ts | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/soapbox/actions/instance.ts b/app/soapbox/actions/instance.ts index 0d6d6c2e40..cd99ac4702 100644 --- a/app/soapbox/actions/instance.ts +++ b/app/soapbox/actions/instance.ts @@ -39,12 +39,16 @@ const needsNodeinfo = (instance: Record): boolean => { export const fetchInstance = createAsyncThunk( '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; }, ); diff --git a/app/soapbox/reducers/meta.ts b/app/soapbox/reducers/meta.ts index ce6848dfe6..aa1df8cc5c 100644 --- a/app/soapbox/reducers/meta.ts +++ b/app/soapbox/reducers/meta.ts @@ -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; }