Merge pull request #17374 from strapi/chore/cleanup-rw-error-handling

Chore: Cleanup review-workflow API error handling
This commit is contained in:
Gustav Hansen 2023-07-19 17:43:40 +02:00 committed by GitHub
commit 9872632b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 30 deletions

View File

@ -86,20 +86,12 @@ export function ReviewWorkflowsCreateView() {
return workflow;
} catch (error) {
// TODO: the current implementation of `formatAPIError` prints all error messages of all details,
// which get's hairy when we have duplicated-name errors, because the same error message is printed
// 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`.
// TODO: this would benefit from a utility to get a formik error
// representation from an API error
if (
error.response.data?.error?.name === 'ValidationError' &&
error.response.data?.error?.details?.errors?.length > 0
) {
toggleNotification({
type: 'warning',
message: error.response.data.error.message,
});
setInitialErrors(
error.response.data?.error?.details?.errors.reduce((acc, error) => {
set(acc, error.path, error.message);
@ -107,13 +99,13 @@ export function ReviewWorkflowsCreateView() {
return acc;
}, {})
);
} else {
toggleNotification({
type: 'warning',
message: formatAPIError(error),
});
}
toggleNotification({
type: 'warning',
message: formatAPIError(error),
});
return null;
}
};

View File

@ -97,20 +97,12 @@ export function ReviewWorkflowsEditView() {
return res;
} catch (error) {
// TODO: the current implementation of `formatAPIError` prints all error messages of all details,
// which get's hairy when we have duplicated-name errors, because the same error message is printed
// 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`.
// TODO: this would benefit from a utility to get a formik error
// representation from an API error
if (
error.response.data?.error?.name === 'ValidationError' &&
error.response.data?.error?.details?.errors?.length > 0
) {
toggleNotification({
type: 'warning',
message: error.response.data.error.message,
});
setInitialErrors(
error.response.data?.error?.details?.errors.reduce((acc, error) => {
set(acc, error.path, error.message);
@ -118,13 +110,13 @@ export function ReviewWorkflowsEditView() {
return acc;
}, {})
);
} else {
toggleNotification({
type: 'warning',
message: formatAPIError(error),
});
}
toggleNotification({
type: 'warning',
message: formatAPIError(error),
});
return null;
}
};