Skip to content

Commit

Permalink
feat(smithy-client): attempt to add ssdk base exception class
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Feb 9, 2022
1 parent 2783e83 commit 98f8140
Showing 1 changed file with 12 additions and 31 deletions.
43 changes: 12 additions & 31 deletions packages/smithy-client/src/exceptions.ts
@@ -1,48 +1,29 @@
import { HttpResponse, MetadataBearer, ResponseMetadata, RetryableTrait, SmithyException } from "@aws-sdk/types";

export class ClientException extends Error {
/**
* The shape ID name of the exception.
*/
readonly name: string;
/**
* Whether the client or server are at fault.
*/
readonly $fault: "client" | "server";

/**
* The service that encountered the exception.
*/
readonly $service?: string;

/**
* Indicates that an error MAY be retried by the client.
*/
readonly $retryable?: RetryableTrait;

readonly $frameworkError?: boolean;
readonly statusCode?: number;

constructor(options: {
name: string;
$fault: "client" | "server";
message?: string;
$service?: string;
$retryable?: RetryableTrait;
$frameworkError?: boolean;
statusCode?: number;
}) {
constructor(options: { name: string; $fault: "client" | "server"; message?: string }) {
super(options.message);
Object.setPrototypeOf(this, ClientException.prototype);
this.name = options.name;
this.$fault = options.$fault;
this.$service = options.$service;
this.$retryable = options.$retryable;
this.$frameworkError = options.$frameworkError;
this.statusCode = options.statusCode;
Object.setPrototypeOf(this, ClientException.prototype);
}
}

/**
* The type of the exception class constructor parameter. The returned type contains the properties
* in the `ExceptionType` but not in the `BaseExceptionType`. If the `BaseExceptionType` contains
* `$metadata` property, it's also included in the returned type.
*/
export type ExceptionOptionType<ExceptionType extends Error, BaseExceptionType extends Error> = Omit<
ExceptionType,
Exclude<keyof BaseExceptionType, "$metadata">
>;

export interface ServiceExceptionOptions extends SmithyException, MetadataBearer {
message?: string;
}
Expand Down

0 comments on commit 98f8140

Please sign in to comment.