Skip to content

Commit

Permalink
Custom error message for non-existing resources
Browse files Browse the repository at this point in the history
  • Loading branch information
garciafdezpatricia committed Jun 27, 2024
1 parent 64241bf commit a6ecf37
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pages/approve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ function Approval({
.catch((error) => setErr(error));
}, [accessRequest, sessionFetch, getNameFromWebId]);

const checkErrorForNonExistingResource = (approveDenyError: any) => {
if (approveDenyError.response && approveDenyError.response.status === 404) {
return "Error: Granting access to a non-existing resource is not supported in Legacy pods.";
}
if ("message" in approveDenyError) {
return `${approveDenyError}`;
}
return `${approveDenyError.message}`;
};

useEffect(fetchAccessRequest, [fetchAccessRequest]);

return (
Expand Down Expand Up @@ -212,9 +222,8 @@ function Approval({
<br />
<br />
<code>
{approveDenyError && "message" in approveDenyError
? `${approveDenyError}`
: `${approveDenyError.message}`}
{approveDenyError &&
`${checkErrorForNonExistingResource(approveDenyError)}`}
</code>
</Modal>
{request && (
Expand Down

0 comments on commit a6ecf37

Please sign in to comment.