diff --git a/frontend/app/api_client.js b/frontend/app/api_client.js index a9e092486..c9a041cc9 100644 --- a/frontend/app/api_client.js +++ b/frontend/app/api_client.js @@ -95,13 +95,11 @@ export default class APIClient { edp = `${ edp }/${ this.siteId }` } return fetch(edp + path, this.init) - .then(response => { + .then((response) => { if (response.ok) { return response } else { - throw new Error( - `! ${this.init.method} error on ${path}; ${response.status}` - ) + return Promise.reject({ message: `! ${this.init.method} error on ${path}; ${response.status}`, response }); } }) } diff --git a/frontend/app/api_middleware.js b/frontend/app/api_middleware.js index f98ad344b..9ef371f01 100644 --- a/frontend/app/api_middleware.js +++ b/frontend/app/api_middleware.js @@ -33,9 +33,10 @@ export default () => (next) => (action) => { next({ type: UPDATE_JWT, data: jwt }); } }) - .catch((e) => { + .catch(async (e) => { + const data = await e.response.json(); logger.error('Error during API request. ', e); - return next({ type: FAILURE, errors: parseError(e) }); + return next({ type: FAILURE, errors: parseError(data.errors) }); }); }; diff --git a/frontend/app/components/Client/CustomFields/CustomFieldForm.js b/frontend/app/components/Client/CustomFields/CustomFieldForm.js index 22108deee..15d24be3d 100644 --- a/frontend/app/components/Client/CustomFields/CustomFieldForm.js +++ b/frontend/app/components/Client/CustomFields/CustomFieldForm.js @@ -39,17 +39,6 @@ class CustomFieldForm extends React.PureComponent { placeholder="Field Name" /> - - {/* TODO: errors state is not updating properly */} - {/* {errors && ( -