fix(ui) - errors reading

This commit is contained in:
Shekar Siri 2023-01-30 12:58:13 +01:00 committed by Taha Yassine Kraiem
parent 6ac1e0c5bd
commit fd88a728d9
4 changed files with 11 additions and 21 deletions

View file

@ -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 });
}
})
}

View file

@ -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) });
});
};

View file

@ -39,17 +39,6 @@ class CustomFieldForm extends React.PureComponent {
placeholder="Field Name"
/>
</Form.Field>
{/* TODO: errors state is not updating properly */}
{/* {errors && (
<div className="mb-3">
{errors.map((error, i) => (
<Message visible={errors} size="mini" error key={i} className={styles.error}>
{error.message}
</Message>
))}
</div>
)} */}
<div className="flex justify-between">
<div className="flex items-center">

View file

@ -11,6 +11,7 @@ import ListItem from './ListItem';
import { confirm } from 'UI';
import AnimatedSVG, { ICONS } from 'Shared/AnimatedSVG/AnimatedSVG';
import { useModal } from 'App/components/Modal';
import { toast } from 'react-toastify';
function CustomFields(props) {
const [currentSite, setCurrentSite] = React.useState(props.sites.get(0));
@ -25,10 +26,11 @@ function CustomFields(props) {
}, []);
const save = (field) => {
props.save(currentSite.id, field).then(() => {
const { errors } = props;
if (!errors || errors.size === 0) {
props.save(currentSite.id, field).then((response) => {
if (!response || !response.errors || response.errors.size === 0) {
hideModal();
} else {
toast.error(response.errors[0]);
}
});
};
@ -73,7 +75,7 @@ function CustomFields(props) {
</div>
<div className="ml-auto">
<Tooltip title="You've reached the limit of 10 metadata." disabled={fields.size < 10}>
<Button disabled={fields.size >= 10} variant="primary" onClick={() => init()}>Add Metadata</Button>
<Button disabled={fields.size >= 10} variant="primary" onClick={() => init()}>Add Metadata</Button>
</Tooltip>
</div>
</div>