fix(ui) - error handle

This commit is contained in:
Shekar Siri 2022-09-19 15:04:31 +05:30
parent 32d916314c
commit e1580e20c3

View file

@ -12,10 +12,14 @@ export default store => next => (action) => {
const client = new APIClient();
return call(client)
.then(response => {
.then(async response => {
if (response.status === 403) {
next({ type: DELETE });
}
if (!response.ok) {
const text = await response.text()
return Promise.reject(text);
}
return response.json()
})
.then(json => json || {}) // TEMP TODO on server: no empty responces
@ -31,7 +35,7 @@ export default store => next => (action) => {
})
.catch((e) => {
logger.error("Error during API request. ", e)
return next({ type: FAILURE, errors: [ "Connection error", String(e) ] });
return next({ type: FAILURE, errors: JSON.parse(e).errors || [] });
});
};