diff --git a/lib/adapters/REST/endpoints/ui-config.ts b/lib/adapters/REST/endpoints/ui-config.ts index c882abab74..6746f6ef7c 100644 --- a/lib/adapters/REST/endpoints/ui-config.ts +++ b/lib/adapters/REST/endpoints/ui-config.ts @@ -16,16 +16,28 @@ export const get: RestEndpoint<'UIConfig', 'get'> = ( return raw.get(http, getUrl(params)) } -export const update: RestEndpoint<'UIConfig', 'update'> = ( +export const update: RestEndpoint<'UIConfig', 'update'> = async ( http: AxiosInstance, params: GetUIConfigParams, rawData: UIConfigProps ) => { const data: SetOptional = copy(rawData) delete data.sys - return raw.put(http, getUrl(params), data, { - headers: { - 'X-Contentful-Version': rawData.sys.version ?? 0, - }, - }) + try { + return await raw.put(http, getUrl(params), data, { + headers: { + 'X-Contentful-Version': rawData.sys.version ?? 0, + }, + }) + } catch (error) { + throw { + sys: { + type: 'Error', + id: 'Failed', + }, + message: 'Update has failed', + details: 'Saved view could not be updated', + message_code: 'savedViews.update.Failed', + } + } } diff --git a/test/unit/adapters/REST/endpoints/ui-config.test.ts b/test/unit/adapters/REST/endpoints/ui-config.test.ts index 424284d784..d9dd153cd8 100644 --- a/test/unit/adapters/REST/endpoints/ui-config.test.ts +++ b/test/unit/adapters/REST/endpoints/ui-config.test.ts @@ -32,4 +32,25 @@ describe('Rest UIConfig', () => { } }) }) + + test('UIConfig update fails with custom error message', async () => { + const errorMessage = 'Network error' + const { adapterMock } = setup(Promise.reject(new Error(errorMessage))) + const entityMock = cloneMock('uiConfig') + const entity = wrapUIConfig((...args) => adapterMock.makeRequest(...args), entityMock) + + try { + await entity.update() + } catch (error) { + expect(error).toEqual({ + sys: { + type: 'Error', + id: 'Failed', + }, + message: 'Update has failed', + details: 'Saved view could not be updated', + message_code: 'savedViews.update.Failed', + }) + } + }) })