Skip to content

Commit 1e96c4b

Browse files
committed
Tighten up typesafety in HTTP error header with unreachable checks
1 parent 85795f6 commit 1e96c4b

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

src/components/view/http/http-error-header.tsx

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { reportError } from '../../../errors';
66

77
import { desktopVersion, versionSatisfies, DESKTOP_HEADER_LIMIT_CONFIGURABLE } from '../../../services/service-versions';
88

9+
import { UnreachableCheck } from '../../../util/error';
910
import { clickOnEnter } from '../../component-utils';
1011
import {
1112
HeaderCard,
@@ -172,9 +173,12 @@ export const HttpErrorHeader = (p: {
172173
return <HeaderCard>
173174
<HeaderText>
174175
<WarningIcon /> {
175-
isInitialRequestError(p.type) || p.type === 'unknown'
176-
? <strong>This request could not be handled</strong>
177-
: <strong>This request was not forwarded successfully</strong>
176+
isInitialRequestError(p.type)
177+
? <strong>This request could not be handled</strong>
178+
: wasNotForwarded(p.type)
179+
? <strong>This request was not forwarded successfully</strong>
180+
: // Forwarded but failed later, or unknown:
181+
<strong>This exchange was not completed successfully</strong>
178182
}
179183
</HeaderText>
180184

@@ -192,8 +196,9 @@ export const HttpErrorHeader = (p: {
192196
? 'included an unparseable URL'
193197
: p.type === 'header-overflow'
194198
? 'headers were too large to be processed'
195-
: // unparseable
196-
'could not be parsed'
199+
: p.type === 'unparseable'
200+
? 'could not be parsed'
201+
: new UnreachableCheck(p.type)
197202
}, so HTTP Toolkit did not handle this request.
198203
</>
199204
: wasNotForwarded(p.type)
@@ -213,29 +218,33 @@ export const HttpErrorHeader = (p: {
213218
? 'was not reachable on your network connection'
214219
: p.type === 'host-not-found' || p.type === 'dns-error'
215220
? 'hostname could be not found'
216-
: // connection-refused
217-
'refused the connection'
221+
: p.type === 'connection-refused'
222+
? 'refused the connection'
223+
: new UnreachableCheck(p.type)
218224
}, so HTTP Toolkit did not forward the request.
219225
</>
220226
: wasTimeout(p.type)
221227
? <>
222228
The request timed out {
223229
p.type === 'client-timeout'
224230
? 'waiting for the client to send the complete request'
225-
: // server-timeout:
226-
'waiting for a response from the server'
231+
: p.type === 'server-timeout'
232+
? 'waiting for a response from the server'
233+
: new UnreachableCheck(p.type)
227234
}
228235
</>
229-
: // Unknown/upstream issue:
230-
<>
236+
: p.type === 'unknown' || p.type === 'connection-reset'
237+
? <>
231238
The request failed because {
232239
p.type === 'connection-reset'
233240
? 'the connection to the server was reset'
234-
: // unknown
235-
'of an unknown error'
241+
: p.type === 'unknown'
242+
? 'of an unknown error'
243+
: new UnreachableCheck(p.type)
236244
}, so HTTP Toolkit could not return a response.
237245
</>
238-
}
246+
: new UnreachableCheck(p.type)
247+
}
239248
</HeaderText>
240249

241250
{ p.type === 'tls-error'
@@ -387,14 +396,14 @@ export const HttpErrorHeader = (p: {
387396
get in touch
388397
</a>.
389398
</HeaderText>
390-
: // 'unknown':
391-
<HeaderText>
399+
: p.type === 'unknown'
400+
? <HeaderText>
392401
It's not clear what's gone wrong here, but for some reason HTTP Toolkit
393402
couldn't successfully and/or securely complete this request.
394403
This might be an intermittent issue, and may be resolved by retrying
395404
the request.
396405
</HeaderText>
397-
}
406+
: new UnreachableCheck(p.type)}
398407

399408
{ isInitialRequestError(p.type) && <HeaderText>
400409
The data shown below is a best guess from the data that was available

0 commit comments

Comments
 (0)