Skip to content

Commit

Permalink
[Issue #3955] Opportunity page returning 500 not 404 errors when Opp …
Browse files Browse the repository at this point in the history
…is not found (#3959)

## Summary
Fixes #3955 

### Time to review: __5 mins__

## Changes proposed
Earlier changes had restructured the error object but the parsing
function wasn't updated to adjust

## Context for reviewers
Steps to test:
1. Open Dev Tools
2. Ensure the Network tab is active
3. Go to any Opportunity page that doesn't exist, like:
http://localhost:3000/1000000
4. Ensure that the page is returning a 404 status not a 500 status
5. Confirm there is no message about malformed error object in the
NextJS console logs server side.
6. It is expected there will be NextJS console logs server side noting
`Failed to render page title due to API error Error: Not Found` and the
associated callstack.

---------

Co-authored-by: doug-s-nava <[email protected]>
  • Loading branch information
mdragon and doug-s-nava authored Feb 26, 2025
1 parent 863a6c5 commit 34179f5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion frontend/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import { QueryParamData } from "src/types/search/searchRequestTypes";

export const parseErrorStatus = (error: ApiRequestError): number => {
const { message } = error;
const cause = error.cause as FrontendErrorDetails;

try {
if (cause?.status) {
return cause.status;
}
const parsedMessage = JSON.parse(message) as { status: number };
return parsedMessage.status;
} catch (e) {
console.error("Malformed error object");
console.error("Malformed error object", e);
return 500;
}
};
Expand Down

0 comments on commit 34179f5

Please sign in to comment.