Skip to content

Commit b8c3a5c

Browse files
authored
Fix typings for AWSError (#3514)
* Fix typings for AWSError AWSError is not a class. It's based on Error but with additional properties on top: https://github.com/aws/aws-sdk-js/blob/master/lib/util.js#L570-L603 By wrongly declaring a class statements like `if (error instanceof AWSError)` would compile but during runtime `AWSError` is `undefined` since it's just a type. Fixing the types prevents this issue. In addition many properties are optional. Declaring them as required can cause type errors and makes mocking more difficult. * fixup! Fix typings for AWSError
1 parent 3ede892 commit b8c3a5c

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "bugfix",
3+
"category": "Types",
4+
"description": "Fix type of AWSError"
5+
}

lib/error.d.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* A structure containing information about a service or networking error.
33
*/
4-
export class AWSError extends Error {
4+
export type AWSError = Error & {
55
/**
66
* A unique short code representing the error that was emitted.
77
*/
@@ -13,37 +13,41 @@ export class AWSError extends Error {
1313
/**
1414
* Whether the error message is retryable.
1515
*/
16-
retryable: boolean;
16+
retryable?: boolean;
1717
/**
1818
* In the case of a request that reached the service, this value contains the response status code.
1919
*/
20-
statusCode: number;
20+
statusCode?: number;
2121
/**
2222
* The date time object when the error occurred.
2323
*/
2424
time: Date;
2525
/**
2626
* Set when a networking error occurs to easily identify the endpoint of the request.
2727
*/
28-
hostname: string;
28+
hostname?: string;
2929
/**
3030
* Set when a networking error occurs to easily identify the region of the request.
3131
*/
32-
region: string;
32+
region?: string;
3333
/**
3434
* Amount of time (in seconds) that the request waited before being resent.
3535
*/
36-
retryDelay: number;
36+
retryDelay?: number;
3737
/**
3838
* The unique request ID associated with the response.
3939
*/
40-
requestId: string;
40+
requestId?: string;
4141
/**
4242
* Second request ID associated with the response from S3.
4343
*/
44-
extendedRequestId: string;
44+
extendedRequestId?: string;
4545
/**
4646
* CloudFront request ID associated with the response.
4747
*/
48-
cfId: string;
49-
}
48+
cfId?: string;
49+
/**
50+
* The original error which caused this Error
51+
*/
52+
originalError?: Error
53+
}

0 commit comments

Comments
 (0)