Skip to content

Commit

Permalink
Fix 410 error on PlainArticlePage
Browse files Browse the repository at this point in the history
Previously this would render differently on client and server due to the
if check only triggering if the `redirectContext` was present.
  • Loading branch information
jnatten committed Nov 14, 2024
1 parent e53db5b commit 40a5904
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/components/ResponseContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class ResponseInfo {
isAccessDeniedError(): boolean {
return this.status === 401 || this.status === 403;
}

isGoneError(): boolean {
return this.status === 410;
}
}

const ResponseContext = createContext<ResponseInfo | undefined>(undefined);
Expand Down
9 changes: 3 additions & 6 deletions src/containers/PlainArticlePage/PlainArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ const PlainArticlePage = () => {
if (loading) {
return <ContentPlaceholder variant="article" />;
}
if (error?.graphQLErrors.some((err) => err.extensions.status === 410) && redirectContext) {
redirectContext.status = 410;
return <UnpublishedResourcePage />;
}

if (responseContext?.status === 410) {
const has410Error = error?.graphQLErrors.some((err) => err.extensions.status === 410);
if (has410Error || responseContext?.isGoneError()) {
if (redirectContext) redirectContext.status = 410;
return <UnpublishedResourcePage />;
}

Expand Down

0 comments on commit 40a5904

Please sign in to comment.