diff --git a/src/components/Dashboard/context/ApiServerContext.jsx b/src/components/Dashboard/context/ApiServerContext.jsx index 453c900c..80a3c615 100644 --- a/src/components/Dashboard/context/ApiServerContext.jsx +++ b/src/components/Dashboard/context/ApiServerContext.jsx @@ -45,6 +45,26 @@ const normalizeUserSettingsCategory = (category) => ? category : {} +const normalizeAxiosBlobError = async (error) => { + const blob = error?.response?.data + if (!(blob instanceof Blob)) { + return error + } + + try { + const text = await blob.text() + try { + error.response.data = JSON.parse(text) + } catch { + error.response.data = { error: text || 'Unknown error' } + } + } catch { + error.response.data = { error: 'Unknown error' } + } + + return error +} + const normalizeUserSettings = (settings = {}) => ({ viewMode: normalizeUserSettingsCategory(settings?.viewMode), filterSidebarVisibility: normalizeUserSettingsCategory( @@ -1717,7 +1737,7 @@ const ApiServerProvider = ({ children }) => { { params: { size }, headers: { - Accept: 'image/jpeg', + Accept: 'image/jpeg, application/json', Authorization: `Bearer ${token}` }, responseType: 'blob' @@ -1728,12 +1748,13 @@ const ApiServerProvider = ({ children }) => { }) return window.URL.createObjectURL(blob) } catch (err) { - if (err.response.status === 404 && show404Error == false) { + if (err.response?.status === 404 && show404Error == false) { return null } console.error(err) + await normalizeAxiosBlobError(err) showError(err, () => { - fetchFileThumbnail(file, size) + fetchFileThumbnail(file, size, show404Error) }) } }