Delete Query UX: Better error handling if query is a part of policies (#2278)

This commit is contained in:
RachelElysia 2021-09-29 15:19:10 -04:00 committed by GitHub
parent 7d5821f527
commit 1b2b926380
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View file

@ -0,0 +1 @@
* Better error handling when a user tries to delete a query that is set in a policy

View file

@ -108,13 +108,26 @@ const ManageQueriesPage = (): JSX.Element => {
toggleRemoveQueryModal();
dispatch(queryActions.loadAll());
})
.catch(() => {
dispatch(
renderFlash(
"error",
`Unable to remove ${queryOrQueries}. Please try again.`
)
);
.catch((response) => {
if (
response.base.slice(0, 47) ===
"the operation violates a foreign key constraint"
) {
dispatch(
renderFlash(
"error",
`Could not delete query because this query is used as a policy. First remove the policy and then try deleting the query again.`
)
);
dispatch(queryActions.loadAll());
} else {
dispatch(
renderFlash(
"error",
`Unable to remove ${queryOrQueries}. Please try again.`
)
);
}
toggleRemoveQueryModal();
});
}, [dispatch, selectedQueryIds, toggleRemoveQueryModal]);