mirror of
https://github.com/strapi/strapi.git
synced 2025-09-23 15:29:27 +00:00
Merge pull request #17374 from strapi/chore/cleanup-rw-error-handling
Chore: Cleanup review-workflow API error handling
This commit is contained in:
commit
9872632b0b
@ -86,20 +86,12 @@ export function ReviewWorkflowsCreateView() {
|
|||||||
|
|
||||||
return workflow;
|
return workflow;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// TODO: the current implementation of `formatAPIError` prints all error messages of all details,
|
// TODO: this would benefit from a utility to get a formik error
|
||||||
// which get's hairy when we have duplicated-name errors, because the same error message is printed
|
// representation from an API error
|
||||||
// several times. What we want instead in these scenarios is to print only the error summary and
|
|
||||||
// display the individual error messages for each field. This is a workaround, until we change the
|
|
||||||
// implementation of `formatAPIError`.
|
|
||||||
if (
|
if (
|
||||||
error.response.data?.error?.name === 'ValidationError' &&
|
error.response.data?.error?.name === 'ValidationError' &&
|
||||||
error.response.data?.error?.details?.errors?.length > 0
|
error.response.data?.error?.details?.errors?.length > 0
|
||||||
) {
|
) {
|
||||||
toggleNotification({
|
|
||||||
type: 'warning',
|
|
||||||
message: error.response.data.error.message,
|
|
||||||
});
|
|
||||||
|
|
||||||
setInitialErrors(
|
setInitialErrors(
|
||||||
error.response.data?.error?.details?.errors.reduce((acc, error) => {
|
error.response.data?.error?.details?.errors.reduce((acc, error) => {
|
||||||
set(acc, error.path, error.message);
|
set(acc, error.path, error.message);
|
||||||
@ -107,12 +99,12 @@ export function ReviewWorkflowsCreateView() {
|
|||||||
return acc;
|
return acc;
|
||||||
}, {})
|
}, {})
|
||||||
);
|
);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
toggleNotification({
|
toggleNotification({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
message: formatAPIError(error),
|
message: formatAPIError(error),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -97,20 +97,12 @@ export function ReviewWorkflowsEditView() {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// TODO: the current implementation of `formatAPIError` prints all error messages of all details,
|
// TODO: this would benefit from a utility to get a formik error
|
||||||
// which get's hairy when we have duplicated-name errors, because the same error message is printed
|
// representation from an API error
|
||||||
// several times. What we want instead in these scenarios is to print only the error summary and
|
|
||||||
// display the individual error messages for each field. This is a workaround, until we change the
|
|
||||||
// implementation of `formatAPIError`.
|
|
||||||
if (
|
if (
|
||||||
error.response.data?.error?.name === 'ValidationError' &&
|
error.response.data?.error?.name === 'ValidationError' &&
|
||||||
error.response.data?.error?.details?.errors?.length > 0
|
error.response.data?.error?.details?.errors?.length > 0
|
||||||
) {
|
) {
|
||||||
toggleNotification({
|
|
||||||
type: 'warning',
|
|
||||||
message: error.response.data.error.message,
|
|
||||||
});
|
|
||||||
|
|
||||||
setInitialErrors(
|
setInitialErrors(
|
||||||
error.response.data?.error?.details?.errors.reduce((acc, error) => {
|
error.response.data?.error?.details?.errors.reduce((acc, error) => {
|
||||||
set(acc, error.path, error.message);
|
set(acc, error.path, error.message);
|
||||||
@ -118,12 +110,12 @@ export function ReviewWorkflowsEditView() {
|
|||||||
return acc;
|
return acc;
|
||||||
}, {})
|
}, {})
|
||||||
);
|
);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
toggleNotification({
|
toggleNotification({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
message: formatAPIError(error),
|
message: formatAPIError(error),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user