Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add more information to errors if we think cookies are missing #2979

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/client/components/GatewayErrorSummary.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,20 @@ export const WithStructuredUnexpectedError = () => (
shortRequestId="123e4567"
></GatewayErrorSummary>
);

const CsrfError: StructuredGatewayError = {
message: 'An unexpected error happened unexpectedly',
severity: 'CSRF',
};

export const WithStructuredCSRFError = () => (
<GatewayErrorSummary
gatewayError={CsrfError}
context={
<p css={[errorContextSpacing, errorContextLastTypeSpacing]}>
Since this was a CSRF error we show cookie help details
</p>
}
shortRequestId="123e4567"
></GatewayErrorSummary>
);
23 changes: 19 additions & 4 deletions src/client/components/GatewayErrorSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,33 @@ interface GateWayErrorSummaryProps

export const GatewayErrorSummary = (props: GateWayErrorSummaryProps) => {
const structuredError = asStructuredError(props.gatewayError);
const fullContext =
props.shortRequestId && structuredError?.severity !== 'BAU'
const fullContext = [
props.context,
// A CSRF error is likely to be the first error a user sees if they have cookies disabled
// so enrich it with some extra details about how to enable cookies.
...(structuredError?.severity === 'CSRF'
? [
<p>
If the problem persists please check if your browser has cookies
enabled. You can find details on how to enable cookies in our{' '}
<a href="https://www.theguardian.com/info/cookies#how-to-manage-cookies-at-the-guardian">
Cookies FAQ
</a>
.
</p>,
]
: []),
...(props.shortRequestId && structuredError?.severity !== 'BAU'
? [
props.context,
<p
css={[errorContextSpacing, errorContextLastTypeSpacing]}
key={'requestId'}
>
Request ID: {props.shortRequestId}
</p>,
]
: props.context;
: []),
];

return (
<ErrorSummary
Expand Down
5 changes: 4 additions & 1 deletion src/server/lib/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ const clientStateFromRequestStateLocals = ({
...clientState,
pageData: {
...clientState.pageData,
formError: CsrfErrors.CSRF_ERROR,
formError: {
message: CsrfErrors.CSRF_ERROR,
severity: 'CSRF',
},
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/model/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export enum SubscribeErrors {

export interface StructuredGatewayError {
message: string;
severity: 'BAU' | 'UNEXPECTED';
severity: 'BAU' | 'CSRF' | 'UNEXPECTED';
}

export type GatewayError = StructuredGatewayError | string;
Expand Down