Skip to content

Commit be41ebf

Browse files
author
Max Beatty
committed
add missing error classes to types
1 parent 250c863 commit be41ebf

2 files changed

Lines changed: 66 additions & 45 deletions

File tree

lib/handler/retry-handler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class RetryHandler {
7070
this.resume = null
7171

7272
// Handle possible onConnect duplication
73-
this.handler.onConnect(reason => {
73+
this.handler.onConnect((reason) => {
7474
this.aborted = true
7575
if (this.abort) {
7676
this.abort(reason)
@@ -202,7 +202,7 @@ class RetryHandler {
202202
this.abort(
203203
new RequestRetryError('Content-Range mismatch', statusCode, {
204204
headers,
205-
count: this.retryCount
205+
data: { count: this.retryCount }
206206
})
207207
)
208208
return false
@@ -213,7 +213,7 @@ class RetryHandler {
213213
this.abort(
214214
new RequestRetryError('ETag mismatch', statusCode, {
215215
headers,
216-
count: this.retryCount
216+
data: { count: this.retryCount }
217217
})
218218
)
219219
return false

types/errors.d.ts

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IncomingHttpHeaders } from "./header";
2-
import Client from './client'
2+
import Client from "./client";
33

4-
export default Errors
4+
export default Errors;
55

66
declare namespace Errors {
77
export class UndiciError extends Error {
@@ -11,118 +11,139 @@ declare namespace Errors {
1111

1212
/** Connect timeout error. */
1313
export class ConnectTimeoutError extends UndiciError {
14-
name: 'ConnectTimeoutError';
15-
code: 'UND_ERR_CONNECT_TIMEOUT';
14+
name: "ConnectTimeoutError";
15+
code: "UND_ERR_CONNECT_TIMEOUT";
1616
}
1717

1818
/** A header exceeds the `headersTimeout` option. */
1919
export class HeadersTimeoutError extends UndiciError {
20-
name: 'HeadersTimeoutError';
21-
code: 'UND_ERR_HEADERS_TIMEOUT';
20+
name: "HeadersTimeoutError";
21+
code: "UND_ERR_HEADERS_TIMEOUT";
2222
}
2323

2424
/** Headers overflow error. */
2525
export class HeadersOverflowError extends UndiciError {
26-
name: 'HeadersOverflowError'
27-
code: 'UND_ERR_HEADERS_OVERFLOW'
26+
name: "HeadersOverflowError";
27+
code: "UND_ERR_HEADERS_OVERFLOW";
2828
}
2929

3030
/** A body exceeds the `bodyTimeout` option. */
3131
export class BodyTimeoutError extends UndiciError {
32-
name: 'BodyTimeoutError';
33-
code: 'UND_ERR_BODY_TIMEOUT';
32+
name: "BodyTimeoutError";
33+
code: "UND_ERR_BODY_TIMEOUT";
3434
}
3535

3636
export class ResponseStatusCodeError extends UndiciError {
37-
constructor (
37+
constructor(
3838
message?: string,
3939
statusCode?: number,
4040
headers?: IncomingHttpHeaders | string[] | null,
4141
body?: null | Record<string, any> | string
4242
);
43-
name: 'ResponseStatusCodeError';
44-
code: 'UND_ERR_RESPONSE_STATUS_CODE';
45-
body: null | Record<string, any> | string
46-
status: number
47-
statusCode: number
43+
name: "ResponseStatusCodeError";
44+
code: "UND_ERR_RESPONSE_STATUS_CODE";
45+
body: null | Record<string, any> | string;
46+
status: number;
47+
statusCode: number;
4848
headers: IncomingHttpHeaders | string[] | null;
4949
}
5050

5151
/** Passed an invalid argument. */
5252
export class InvalidArgumentError extends UndiciError {
53-
name: 'InvalidArgumentError';
54-
code: 'UND_ERR_INVALID_ARG';
53+
name: "InvalidArgumentError";
54+
code: "UND_ERR_INVALID_ARG";
5555
}
5656

5757
/** Returned an invalid value. */
5858
export class InvalidReturnValueError extends UndiciError {
59-
name: 'InvalidReturnValueError';
60-
code: 'UND_ERR_INVALID_RETURN_VALUE';
59+
name: "InvalidReturnValueError";
60+
code: "UND_ERR_INVALID_RETURN_VALUE";
6161
}
6262

6363
/** The request has been aborted by the user. */
6464
export class RequestAbortedError extends UndiciError {
65-
name: 'AbortError';
66-
code: 'UND_ERR_ABORTED';
65+
name: "AbortError";
66+
code: "UND_ERR_ABORTED";
6767
}
6868

6969
/** Expected error with reason. */
7070
export class InformationalError extends UndiciError {
71-
name: 'InformationalError';
72-
code: 'UND_ERR_INFO';
71+
name: "InformationalError";
72+
code: "UND_ERR_INFO";
7373
}
7474

7575
/** Request body length does not match content-length header. */
7676
export class RequestContentLengthMismatchError extends UndiciError {
77-
name: 'RequestContentLengthMismatchError';
78-
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH';
77+
name: "RequestContentLengthMismatchError";
78+
code: "UND_ERR_REQ_CONTENT_LENGTH_MISMATCH";
7979
}
8080

8181
/** Response body length does not match content-length header. */
8282
export class ResponseContentLengthMismatchError extends UndiciError {
83-
name: 'ResponseContentLengthMismatchError';
84-
code: 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH';
83+
name: "ResponseContentLengthMismatchError";
84+
code: "UND_ERR_RES_CONTENT_LENGTH_MISMATCH";
8585
}
8686

8787
/** Trying to use a destroyed client. */
8888
export class ClientDestroyedError extends UndiciError {
89-
name: 'ClientDestroyedError';
90-
code: 'UND_ERR_DESTROYED';
89+
name: "ClientDestroyedError";
90+
code: "UND_ERR_DESTROYED";
9191
}
9292

9393
/** Trying to use a closed client. */
9494
export class ClientClosedError extends UndiciError {
95-
name: 'ClientClosedError';
96-
code: 'UND_ERR_CLOSED';
95+
name: "ClientClosedError";
96+
code: "UND_ERR_CLOSED";
9797
}
9898

9999
/** There is an error with the socket. */
100100
export class SocketError extends UndiciError {
101-
name: 'SocketError';
102-
code: 'UND_ERR_SOCKET';
103-
socket: Client.SocketInfo | null
101+
name: "SocketError";
102+
code: "UND_ERR_SOCKET";
103+
socket: Client.SocketInfo | null;
104104
}
105105

106106
/** Encountered unsupported functionality. */
107107
export class NotSupportedError extends UndiciError {
108-
name: 'NotSupportedError';
109-
code: 'UND_ERR_NOT_SUPPORTED';
108+
name: "NotSupportedError";
109+
code: "UND_ERR_NOT_SUPPORTED";
110110
}
111111

112112
/** No upstream has been added to the BalancedPool. */
113113
export class BalancedPoolMissingUpstreamError extends UndiciError {
114-
name: 'MissingUpstreamError';
115-
code: 'UND_ERR_BPL_MISSING_UPSTREAM';
114+
name: "MissingUpstreamError";
115+
code: "UND_ERR_BPL_MISSING_UPSTREAM";
116116
}
117117

118118
export class HTTPParserError extends UndiciError {
119-
name: 'HTTPParserError';
119+
name: "HTTPParserError";
120120
code: string;
121121
}
122122

123123
/** The response exceed the length allowed. */
124124
export class ResponseExceededMaxSizeError extends UndiciError {
125-
name: 'ResponseExceededMaxSizeError';
126-
code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE';
125+
name: "ResponseExceededMaxSizeError";
126+
code: "UND_ERR_RES_EXCEEDED_MAX_SIZE";
127+
}
128+
129+
export class RequestRetryError extends UndiciError {
130+
constructor(
131+
message: string,
132+
statusCode: number,
133+
headers?: IncomingHttpHeaders | string[] | null,
134+
body?: null | Record<string, any> | string
135+
);
136+
name: "RequestRetryError";
137+
code: "UND_ERR_REQ_RETRY";
138+
statusCode: number;
139+
data: {
140+
count: number;
141+
};
142+
headers: Record<string, string | string[]>;
143+
}
144+
145+
export class SecureProxyConnectionError extends UndiciError {
146+
name: "SecureProxyConnectionError";
147+
code: "UND_ERR_PRX_TLS";
127148
}
128149
}

0 commit comments

Comments
 (0)