Skip to content

Commit ca64fee

Browse files
authored
feat(clients): generate service exceptions as classes (#3267)
* fix(smithy-client): decorateServiceException not to overwrite modeled members * feat(clients): throw exceptions as ServiceException class
1 parent c827d5c commit ca64fee

File tree

1,236 files changed

+187175
-448957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,236 files changed

+187175
-448957
lines changed

clients/client-accessanalyzer/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./AccessAnalyzerClient";
33
export * from "./commands";
44
export * from "./models";
55
export * from "./pagination";
6+
export { AccessAnalyzerServiceException } from "./models/AccessAnalyzerServiceException";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {
2+
ServiceException as __ServiceException,
3+
ServiceExceptionOptions as __ServiceExceptionOptions,
4+
} from "@aws-sdk/smithy-client";
5+
6+
/**
7+
* Base exception class for all service exceptions from AccessAnalyzer service.
8+
*/
9+
export class AccessAnalyzerServiceException extends __ServiceException {
10+
/**
11+
* @internal
12+
*/
13+
constructor(options: __ServiceExceptionOptions) {
14+
super(options);
15+
Object.setPrototypeOf(this, AccessAnalyzerServiceException.prototype);
16+
}
17+
}

clients/client-accessanalyzer/src/models/models_0.ts

+121-32
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
import { MetadataBearer as $MetadataBearer, SmithyException as __SmithyException } from "@aws-sdk/types";
1+
import { ExceptionOptionType as __ExceptionOptionType } from "@aws-sdk/smithy-client";
2+
import { MetadataBearer as $MetadataBearer } from "@aws-sdk/types";
3+
4+
import { AccessAnalyzerServiceException as __BaseException } from "./AccessAnalyzerServiceException";
25

36
/**
47
* <p>You do not have sufficient access to perform this action.</p>
58
*/
6-
export interface AccessDeniedException extends __SmithyException, $MetadataBearer {
7-
name: "AccessDeniedException";
8-
$fault: "client";
9-
message: string | undefined;
9+
export class AccessDeniedException extends __BaseException {
10+
readonly name: "AccessDeniedException" = "AccessDeniedException";
11+
readonly $fault: "client" = "client";
12+
/**
13+
* @internal
14+
*/
15+
constructor(opts: __ExceptionOptionType<AccessDeniedException, __BaseException>) {
16+
super({
17+
name: "AccessDeniedException",
18+
$fault: "client",
19+
...opts,
20+
});
21+
Object.setPrototypeOf(this, AccessDeniedException.prototype);
22+
}
1023
}
1124

1225
/**
1326
* <p>A conflict exception error.</p>
1427
*/
15-
export interface ConflictException extends __SmithyException, $MetadataBearer {
16-
name: "ConflictException";
17-
$fault: "client";
18-
message: string | undefined;
28+
export class ConflictException extends __BaseException {
29+
readonly name: "ConflictException" = "ConflictException";
30+
readonly $fault: "client" = "client";
1931
/**
2032
* <p>The ID of the resource.</p>
2133
*/
@@ -25,6 +37,20 @@ export interface ConflictException extends __SmithyException, $MetadataBearer {
2537
* <p>The resource type.</p>
2638
*/
2739
resourceType: string | undefined;
40+
41+
/**
42+
* @internal
43+
*/
44+
constructor(opts: __ExceptionOptionType<ConflictException, __BaseException>) {
45+
super({
46+
name: "ConflictException",
47+
$fault: "client",
48+
...opts,
49+
});
50+
Object.setPrototypeOf(this, ConflictException.prototype);
51+
this.resourceId = opts.resourceId;
52+
this.resourceType = opts.resourceType;
53+
}
2854
}
2955

3056
/**
@@ -98,24 +124,35 @@ export namespace CreateArchiveRuleRequest {
98124
/**
99125
* <p>Internal server error.</p>
100126
*/
101-
export interface InternalServerException extends __SmithyException, $MetadataBearer {
102-
name: "InternalServerException";
103-
$fault: "server";
104-
$retryable: {};
105-
message: string | undefined;
127+
export class InternalServerException extends __BaseException {
128+
readonly name: "InternalServerException" = "InternalServerException";
129+
readonly $fault: "server" = "server";
130+
$retryable = {};
106131
/**
107132
* <p>The seconds to wait to retry.</p>
108133
*/
109134
retryAfterSeconds?: number;
135+
136+
/**
137+
* @internal
138+
*/
139+
constructor(opts: __ExceptionOptionType<InternalServerException, __BaseException>) {
140+
super({
141+
name: "InternalServerException",
142+
$fault: "server",
143+
...opts,
144+
});
145+
Object.setPrototypeOf(this, InternalServerException.prototype);
146+
this.retryAfterSeconds = opts.retryAfterSeconds;
147+
}
110148
}
111149

112150
/**
113151
* <p>The specified resource could not be found.</p>
114152
*/
115-
export interface ResourceNotFoundException extends __SmithyException, $MetadataBearer {
116-
name: "ResourceNotFoundException";
117-
$fault: "client";
118-
message: string | undefined;
153+
export class ResourceNotFoundException extends __BaseException {
154+
readonly name: "ResourceNotFoundException" = "ResourceNotFoundException";
155+
readonly $fault: "client" = "client";
119156
/**
120157
* <p>The ID of the resource.</p>
121158
*/
@@ -125,15 +162,28 @@ export interface ResourceNotFoundException extends __SmithyException, $MetadataB
125162
* <p>The type of the resource.</p>
126163
*/
127164
resourceType: string | undefined;
165+
166+
/**
167+
* @internal
168+
*/
169+
constructor(opts: __ExceptionOptionType<ResourceNotFoundException, __BaseException>) {
170+
super({
171+
name: "ResourceNotFoundException",
172+
$fault: "client",
173+
...opts,
174+
});
175+
Object.setPrototypeOf(this, ResourceNotFoundException.prototype);
176+
this.resourceId = opts.resourceId;
177+
this.resourceType = opts.resourceType;
178+
}
128179
}
129180

130181
/**
131182
* <p>Service quote met error.</p>
132183
*/
133-
export interface ServiceQuotaExceededException extends __SmithyException, $MetadataBearer {
134-
name: "ServiceQuotaExceededException";
135-
$fault: "client";
136-
message: string | undefined;
184+
export class ServiceQuotaExceededException extends __BaseException {
185+
readonly name: "ServiceQuotaExceededException" = "ServiceQuotaExceededException";
186+
readonly $fault: "client" = "client";
137187
/**
138188
* <p>The resource ID.</p>
139189
*/
@@ -143,22 +193,48 @@ export interface ServiceQuotaExceededException extends __SmithyException, $Metad
143193
* <p>The resource type.</p>
144194
*/
145195
resourceType: string | undefined;
196+
197+
/**
198+
* @internal
199+
*/
200+
constructor(opts: __ExceptionOptionType<ServiceQuotaExceededException, __BaseException>) {
201+
super({
202+
name: "ServiceQuotaExceededException",
203+
$fault: "client",
204+
...opts,
205+
});
206+
Object.setPrototypeOf(this, ServiceQuotaExceededException.prototype);
207+
this.resourceId = opts.resourceId;
208+
this.resourceType = opts.resourceType;
209+
}
146210
}
147211

148212
/**
149213
* <p>Throttling limit exceeded error.</p>
150214
*/
151-
export interface ThrottlingException extends __SmithyException, $MetadataBearer {
152-
name: "ThrottlingException";
153-
$fault: "client";
154-
$retryable: {
155-
throttling: true;
215+
export class ThrottlingException extends __BaseException {
216+
readonly name: "ThrottlingException" = "ThrottlingException";
217+
readonly $fault: "client" = "client";
218+
$retryable = {
219+
throttling: true,
156220
};
157-
message: string | undefined;
158221
/**
159222
* <p>The seconds to wait to retry.</p>
160223
*/
161224
retryAfterSeconds?: number;
225+
226+
/**
227+
* @internal
228+
*/
229+
constructor(opts: __ExceptionOptionType<ThrottlingException, __BaseException>) {
230+
super({
231+
name: "ThrottlingException",
232+
$fault: "client",
233+
...opts,
234+
});
235+
Object.setPrototypeOf(this, ThrottlingException.prototype);
236+
this.retryAfterSeconds = opts.retryAfterSeconds;
237+
}
162238
}
163239

164240
/**
@@ -195,10 +271,9 @@ export enum ValidationExceptionReason {
195271
/**
196272
* <p>Validation exception error.</p>
197273
*/
198-
export interface ValidationException extends __SmithyException, $MetadataBearer {
199-
name: "ValidationException";
200-
$fault: "client";
201-
message: string | undefined;
274+
export class ValidationException extends __BaseException {
275+
readonly name: "ValidationException" = "ValidationException";
276+
readonly $fault: "client" = "client";
202277
/**
203278
* <p>The reason for the exception.</p>
204279
*/
@@ -208,6 +283,20 @@ export interface ValidationException extends __SmithyException, $MetadataBearer
208283
* <p>A list of fields that didn't validate.</p>
209284
*/
210285
fieldList?: ValidationExceptionField[];
286+
287+
/**
288+
* @internal
289+
*/
290+
constructor(opts: __ExceptionOptionType<ValidationException, __BaseException>) {
291+
super({
292+
name: "ValidationException",
293+
$fault: "client",
294+
...opts,
295+
});
296+
Object.setPrototypeOf(this, ValidationException.prototype);
297+
this.reason = opts.reason;
298+
this.fieldList = opts.fieldList;
299+
}
211300
}
212301

213302
/**

0 commit comments

Comments
 (0)