Check that soapbox.json is really an object before importing, fixes #376

better-thread-display
Alex Gleason 2020-09-01 00:02:01 -05:00
rodzic c8e6bd9540
commit cd5ee4837c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 8 dodań i 5 usunięć

Wyświetl plik

@ -40,8 +40,9 @@ export function fetchSoapboxConfig() {
export function fetchSoapboxJson() {
return (dispatch, getState) => {
api(getState).get('/instance/soapbox.json').then(response => {
dispatch(importSoapboxConfig(response.data));
api(getState).get('/instance/soapbox.json').then(({ data }) => {
if (!isObject(data)) throw 'soapbox.json failed';
dispatch(importSoapboxConfig(data));
}).catch(error => {
dispatch(soapboxConfigFail(error));
});
@ -56,12 +57,14 @@ export function importSoapboxConfig(soapboxConfig) {
}
export function soapboxConfigFail(error) {
if (!error.response) {
console.error('Unable to obtain soapbox configuration: ' + error);
}
return {
type: SOAPBOX_CONFIG_REQUEST_FAIL,
error,
skipAlert: true,
};
}
// https://stackoverflow.com/a/46663081
function isObject(o) {
return o instanceof Object && o.constructor === Object;
}