mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix: JSON parsing in backend_srv (#45598)
* fix(plugins/state): console log errors during install / uninstall * fix(backend_srv): catch JSON parse errors Sometimes it can happen that a backend API responses says that it's returning with a JSON content-type, however it actually returns an invalid JSON (e.g. an empty body) - in which case the backendSrv() request errors out.
This commit is contained in:
@@ -105,7 +105,12 @@ export async function parseResponseBody<T>(
|
|||||||
return response.blob() as any;
|
return response.blob() as any;
|
||||||
|
|
||||||
case 'json':
|
case 'json':
|
||||||
return response.json();
|
try {
|
||||||
|
return await response.json();
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`${response.url} returned an invalid JSON -`, err);
|
||||||
|
return {} as unknown as T;
|
||||||
|
}
|
||||||
|
|
||||||
case 'text':
|
case 'text':
|
||||||
return response.text() as any;
|
return response.text() as any;
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ export const install = createAsyncThunk(
|
|||||||
|
|
||||||
return { id, changes } as Update<CatalogPlugin>;
|
return { id, changes } as Update<CatalogPlugin>;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
|
||||||
return thunkApi.rejectWithValue('Unknown error.');
|
return thunkApi.rejectWithValue('Unknown error.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +92,8 @@ export const uninstall = createAsyncThunk(`${STATE_PREFIX}/uninstall`, async (id
|
|||||||
changes: { isInstalled: false, installedVersion: undefined },
|
changes: { isInstalled: false, installedVersion: undefined },
|
||||||
} as Update<CatalogPlugin>;
|
} as Update<CatalogPlugin>;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
|
||||||
return thunkApi.rejectWithValue('Unknown error.');
|
return thunkApi.rejectWithValue('Unknown error.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user