Skip to content

Commit 22f0e45

Browse files
committed
feat: Add more information to errors if we think cookies are missing
1 parent 71afae6 commit 22f0e45

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/client/components/GatewayErrorSummary.stories.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,20 @@ export const WithStructuredUnexpectedError = () => (
6161
shortRequestId="123e4567"
6262
></GatewayErrorSummary>
6363
);
64+
65+
const CsrfError: StructuredGatewayError = {
66+
message: 'An unexpected error happened unexpectedly',
67+
severity: 'CSRF',
68+
};
69+
70+
export const WithStructuredCSRFError = () => (
71+
<GatewayErrorSummary
72+
gatewayError={CsrfError}
73+
context={
74+
<p css={[errorContextSpacing, errorContextLastTypeSpacing]}>
75+
Since this was a CSRF error we show cookie help details
76+
</p>
77+
}
78+
shortRequestId="123e4567"
79+
></GatewayErrorSummary>
80+
);

src/client/components/GatewayErrorSummary.tsx

+19-4
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,33 @@ interface GateWayErrorSummaryProps
1818

1919
export const GatewayErrorSummary = (props: GateWayErrorSummaryProps) => {
2020
const structuredError = asStructuredError(props.gatewayError);
21-
const fullContext =
22-
props.shortRequestId && structuredError?.severity !== 'BAU'
21+
const fullContext = [
22+
props.context,
23+
// A CSRF error is likely to be the first error a user sees if they have cookies disabled
24+
// so enrich it with some extra details about how to enable cookies.
25+
...(structuredError?.severity === 'CSRF'
26+
? [
27+
<p>
28+
If the problem persists please check if your browser has cookies
29+
enabled. You can find details on how to enable cookies in our{' '}
30+
<a href="https://www.theguardian.com/info/cookies#how-to-manage-cookies-at-the-guardian">
31+
Cookies FAQ
32+
</a>
33+
.
34+
</p>,
35+
]
36+
: []),
37+
...(props.shortRequestId && structuredError?.severity !== 'BAU'
2338
? [
24-
props.context,
2539
<p
2640
css={[errorContextSpacing, errorContextLastTypeSpacing]}
2741
key={'requestId'}
2842
>
2943
Request ID: {props.shortRequestId}
3044
</p>,
3145
]
32-
: props.context;
46+
: []),
47+
];
3348

3449
return (
3550
<ErrorSummary

src/server/lib/renderer.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ const clientStateFromRequestStateLocals = ({
8686
...clientState,
8787
pageData: {
8888
...clientState.pageData,
89-
formError: CsrfErrors.CSRF_ERROR,
89+
formError: {
90+
message: CsrfErrors.CSRF_ERROR,
91+
severity: 'CSRF',
92+
},
9093
},
9194
};
9295
}

src/shared/model/Errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export enum SubscribeErrors {
9292

9393
export interface StructuredGatewayError {
9494
message: string;
95-
severity: 'BAU' | 'UNEXPECTED';
95+
severity: 'BAU' | 'CSRF' | 'UNEXPECTED';
9696
}
9797

9898
export type GatewayError = StructuredGatewayError | string;

0 commit comments

Comments
 (0)