Skip to content

Commit 98f8140

Browse files
committed
feat(smithy-client): attempt to add ssdk base exception class
1 parent 2783e83 commit 98f8140

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

packages/smithy-client/src/exceptions.ts

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,29 @@
11
import { HttpResponse, MetadataBearer, ResponseMetadata, RetryableTrait, SmithyException } from "@aws-sdk/types";
22

33
export class ClientException extends Error {
4-
/**
5-
* The shape ID name of the exception.
6-
*/
7-
readonly name: string;
84
/**
95
* Whether the client or server are at fault.
106
*/
117
readonly $fault: "client" | "server";
128

13-
/**
14-
* The service that encountered the exception.
15-
*/
16-
readonly $service?: string;
17-
18-
/**
19-
* Indicates that an error MAY be retried by the client.
20-
*/
21-
readonly $retryable?: RetryableTrait;
22-
23-
readonly $frameworkError?: boolean;
24-
readonly statusCode?: number;
25-
26-
constructor(options: {
27-
name: string;
28-
$fault: "client" | "server";
29-
message?: string;
30-
$service?: string;
31-
$retryable?: RetryableTrait;
32-
$frameworkError?: boolean;
33-
statusCode?: number;
34-
}) {
9+
constructor(options: { name: string; $fault: "client" | "server"; message?: string }) {
3510
super(options.message);
11+
Object.setPrototypeOf(this, ClientException.prototype);
3612
this.name = options.name;
3713
this.$fault = options.$fault;
38-
this.$service = options.$service;
39-
this.$retryable = options.$retryable;
40-
this.$frameworkError = options.$frameworkError;
41-
this.statusCode = options.statusCode;
42-
Object.setPrototypeOf(this, ClientException.prototype);
4314
}
4415
}
4516

17+
/**
18+
* The type of the exception class constructor parameter. The returned type contains the properties
19+
* in the `ExceptionType` but not in the `BaseExceptionType`. If the `BaseExceptionType` contains
20+
* `$metadata` property, it's also included in the returned type.
21+
*/
22+
export type ExceptionOptionType<ExceptionType extends Error, BaseExceptionType extends Error> = Omit<
23+
ExceptionType,
24+
Exclude<keyof BaseExceptionType, "$metadata">
25+
>;
26+
4627
export interface ServiceExceptionOptions extends SmithyException, MetadataBearer {
4728
message?: string;
4829
}

0 commit comments

Comments
 (0)