File tree 4 files changed +41
-6
lines changed
4 files changed +41
-6
lines changed Original file line number Diff line number Diff line change @@ -61,3 +61,20 @@ export const WithStructuredUnexpectedError = () => (
61
61
shortRequestId = "123e4567"
62
62
> </ GatewayErrorSummary >
63
63
) ;
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
+ ) ;
Original file line number Diff line number Diff line change @@ -18,18 +18,33 @@ interface GateWayErrorSummaryProps
18
18
19
19
export const GatewayErrorSummary = ( props : GateWayErrorSummaryProps ) => {
20
20
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'
23
38
? [
24
- props . context ,
25
39
< p
26
40
css = { [ errorContextSpacing , errorContextLastTypeSpacing ] }
27
41
key = { 'requestId' }
28
42
>
29
43
Request ID: { props . shortRequestId }
30
44
</ p > ,
31
45
]
32
- : props . context ;
46
+ : [ ] ) ,
47
+ ] ;
33
48
34
49
return (
35
50
< ErrorSummary
Original file line number Diff line number Diff line change @@ -86,7 +86,10 @@ const clientStateFromRequestStateLocals = ({
86
86
...clientState ,
87
87
pageData : {
88
88
...clientState . pageData ,
89
- formError : CsrfErrors . CSRF_ERROR ,
89
+ formError : {
90
+ message : CsrfErrors . CSRF_ERROR ,
91
+ severity : 'CSRF' ,
92
+ } ,
90
93
} ,
91
94
} ;
92
95
}
Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ export enum SubscribeErrors {
92
92
93
93
export interface StructuredGatewayError {
94
94
message : string ;
95
- severity : 'BAU' | 'UNEXPECTED' ;
95
+ severity : 'BAU' | 'CSRF' | ' UNEXPECTED';
96
96
}
97
97
98
98
export type GatewayError = StructuredGatewayError | string ;
You can’t perform that action at this time.
0 commit comments