Form updates
This commit is contained in:
@@ -71,36 +71,29 @@ export function useMutationAPI() {
|
||||
const response = await fetch(`${url}/${endpoint}`, options);
|
||||
if (!response.ok) {
|
||||
const responseData = await response.json();
|
||||
if (typeof responseData.detail !== 'string') {
|
||||
const errorResponse = JSON.stringify({
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
method: options.method,
|
||||
endpoint: endpoint,
|
||||
msg: responseData.detail[0]?.msg,
|
||||
loc: responseData.detail[0]?.loc,
|
||||
type: responseData.detail[0]?.type,
|
||||
});
|
||||
throw new Error(errorResponse);
|
||||
if (typeof responseData === 'object') {
|
||||
if (responseData.error.code === 'ER_DUP_ENTRY') {
|
||||
setTimeout(() => {
|
||||
notifications.update({
|
||||
id: id,
|
||||
loading: false,
|
||||
title: (
|
||||
<Text fw={600} c={'var(--mantine-color-accent-0)'}>
|
||||
{method} Failure!
|
||||
</Text>
|
||||
),
|
||||
message: (
|
||||
<Text c={'var(--mantine-color-primary-0)'}>
|
||||
Entry with that name already exists.
|
||||
</Text>
|
||||
),
|
||||
autoClose: 2500,
|
||||
icon: <FaCheck size={24} />,
|
||||
});
|
||||
}, 2500);
|
||||
}
|
||||
}
|
||||
if (typeof responseData.detail === 'object') {
|
||||
const errorResponse = JSON.stringify({
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
method: options.method,
|
||||
endpoint: endpoint,
|
||||
msg: responseData.detail.message,
|
||||
});
|
||||
throw new Error(errorResponse);
|
||||
}
|
||||
const errorResponse = JSON.stringify({
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
method: options.method,
|
||||
endpoint: endpoint,
|
||||
msg: responseData.detail,
|
||||
});
|
||||
throw new Error(errorResponse);
|
||||
return await responseData;
|
||||
}
|
||||
setTimeout(() => {
|
||||
notifications.update({
|
||||
|
||||
Reference in New Issue
Block a user