Standalone: fallback to limited featureset when authenticated fetch is enabled

This commit is contained in:
Alex Gleason 2021-08-31 09:02:43 -07:00
parent 777c975693
commit 474d67f591
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -13,12 +13,21 @@ import { authLoggedIn, verifyCredentials, switchAccount } from 'soapbox/actions/
import { parseBaseURL } from 'soapbox/utils/auth'; import { parseBaseURL } from 'soapbox/utils/auth';
import { getFeatures } from 'soapbox/utils/features'; import { getFeatures } from 'soapbox/utils/features';
import sourceCode from 'soapbox/utils/code'; import sourceCode from 'soapbox/utils/code';
import { fromJS } from 'immutable'; import { Map as ImmutableMap, fromJS } from 'immutable';
const fetchExternalInstance = baseURL => { const fetchExternalInstance = baseURL => {
return baseClient(null, baseURL) return baseClient(null, baseURL)
.get('/api/v1/instance') .get('/api/v1/instance')
.then(({ data: instance }) => fromJS(instance)); .then(({ data: instance }) => fromJS(instance))
.catch(error => {
if (error.response.status === 401) {
// Authenticated fetch is enabled.
// Continue with a limited featureset.
return ImmutableMap({ version: '0.0.0' });
} else {
throw error;
}
});
}; };
export function createAppAndRedirect(host) { export function createAppAndRedirect(host) {