Skip to content

Commit e2031d5

Browse files
committed
rename ClientException to SmithyClient in server-common package
1 parent dfa2605 commit e2031d5

File tree

9 files changed

+48
-32
lines changed

9 files changed

+48
-32
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ private void writeServerResponseTest(OperationShape operation, HttpResponseTestC
741741
writer.write("const request = new HttpRequest({method: 'POST', hostname: 'example.com'});");
742742

743743
// Create a new serializer factory that always returns our test serializer.
744-
writer.addImport("SmithyException", "__SmithyException", "@aws-sdk/types");
744+
writer.addImport("SmithyException", "__SmithyException", "@aws-smithy/server-common");
745745
writer.addImport("OperationSerializer", "__OperationSerializer", "@aws-smithy/server-common");
746746
writer.openBlock("const serFn: (op: $1T) => __OperationSerializer<$2T<{}>, $1T, __SmithyException> = (op) =>"
747747
+ " { return new TestSerializer(); };", serviceOperationsSymbol, serviceSymbol);

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private static void addCommonHandlerImports(TypeScriptWriter writer) {
208208
writer.addImport("SmithyFrameworkException", "__SmithyFrameworkException", "@aws-smithy/server-common");
209209
writer.addImport("HttpRequest", "__HttpRequest", "@aws-sdk/protocol-http");
210210
writer.addImport("HttpResponse", "__HttpResponse", "@aws-sdk/protocol-http");
211-
writer.addImport("SmithyException", "__SmithyException", "@aws-sdk/types");
211+
writer.addImport("SmithyException", "__SmithyException", "@aws-smithy/server-common");
212212
writer.addImport("ValidationCustomizer", "__ValidationCustomizer", "@aws-smithy/server-common");
213213
}
214214

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ void writeErrorConstructor(TypeScriptWriter writer, Shape shape, boolean isServe
130130
ErrorTrait errorTrait = shape.getTrait(ErrorTrait.class).orElseThrow(IllegalStateException::new);
131131
Symbol symbol = symbolProvider.toSymbol(shape);
132132
if (isServerSdk) {
133-
// TODO: change to import from @aws-smithy/server-common
134-
writer.addImport("ClientException", "__BaseException", "@aws-sdk/smithy-client");
133+
writer.addImport("SmithyException", "__BaseException", TypeScriptDependency.SERVER_COMMON.packageName);
135134
} else {
136-
writer.addImport("ServiceException", "__BaseException", "@aws-sdk/smithy-client");
135+
writer.addImport("ServiceException", "__BaseException", TypeScriptDependency.AWS_SMITHY_CLIENT.packageName);
137136
writer.writeDocs("@internal");
138137
}
139-
writer.addImport("ExceptionOptionType", "__ExceptionOptionType", "@aws-sdk/smithy-client");
138+
writer.addImport("ExceptionOptionType", "__ExceptionOptionType",
139+
TypeScriptDependency.AWS_SMITHY_CLIENT.packageName);
140140
writer.openBlock("constructor(opts: __ExceptionOptionType<$L, __BaseException>) {", symbol.getName());
141141
writer.openBlock("super({", "});", () -> {
142142
writer.write("name: $S,", shape.getId().getName());

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public void generateServiceHandlerFactory(GenerationContext context) {
363363
writer.indent();
364364

365365
generateServiceMux(context);
366-
writer.addImport("SmithyException", "__SmithyException", "@aws-sdk/types");
366+
writer.addImport("SmithyException", "__SmithyException", "@aws-smithy/server-common");
367367
writer.openBlock("const serFn: (op: $1T) => __OperationSerializer<$2T<Context>, $1T, __SmithyException> = "
368368
+ "(op) => {", "};", operationsSymbol, serviceSymbol, () -> {
369369
writer.openBlock("switch (op) {", "}", () -> {

smithy-typescript-ssdk-libs/server-common/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"license": "Apache-2.0",
2121
"dependencies": {
2222
"@aws-sdk/protocol-http": "3.40.0",
23-
"@aws-sdk/smithy-client": "3.41.0",
2423
"@aws-sdk/types": "3.40.0",
2524
"tslib": "^1.8.0",
2625
"re2-wasm": "^1.0.2"

smithy-typescript-ssdk-libs/server-common/src/errors.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
import { SmithyException } from "@aws-sdk/smithy-client";
16+
export class SmithyException extends Error {
17+
/**
18+
* Whether the client or server are at fault.
19+
*/
20+
readonly $fault: "client" | "server";
21+
22+
constructor(options: { name: string; $fault: "client" | "server"; message?: string }) {
23+
super(options.message);
24+
Object.setPrototypeOf(this, SmithyException.prototype);
25+
this.name = options.name;
26+
this.$fault = options.$fault;
27+
}
28+
}
1729

1830
export type SmithyFrameworkException =
1931
| InternalFailureException
@@ -29,37 +41,57 @@ export const isFrameworkException = (error: any): error is SmithyFrameworkExcept
2941
return error.$frameworkError;
3042
};
3143

32-
export class InternalFailureException implements SmithyException {
44+
export class InternalFailureException extends SmithyException {
3345
readonly name = "InternalFailure";
3446
readonly $fault = "server";
3547
readonly statusCode = 500;
3648
readonly $frameworkError = true;
49+
constructor() {
50+
super({ name: "InternalFailure", $fault: "server" });
51+
Object.setPrototypeOf(this, InternalFailureException.prototype);
52+
}
3753
}
3854

39-
export class UnknownOperationException implements SmithyException {
55+
export class UnknownOperationException extends SmithyException {
4056
readonly name = "UnknownOperationException";
4157
readonly $fault = "client";
4258
readonly statusCode = 404;
4359
readonly $frameworkError = true;
60+
constructor() {
61+
super({ name: "UnknownOperationException", $fault: "client" });
62+
Object.setPrototypeOf(this, UnknownOperationException.prototype);
63+
}
4464
}
4565

46-
export class SerializationException implements SmithyException {
66+
export class SerializationException extends SmithyException {
4767
readonly name = "SerializationException";
4868
readonly $fault = "client";
4969
readonly statusCode = 400;
5070
readonly $frameworkError = true;
71+
constructor() {
72+
super({ name: "SerializationException", $fault: "client" });
73+
Object.setPrototypeOf(this, SerializationException.prototype);
74+
}
5175
}
5276

53-
export class UnsupportedMediaTypeException implements SmithyException {
77+
export class UnsupportedMediaTypeException extends SmithyException {
5478
readonly name = "UnsupportedMediaTypeException";
5579
readonly $fault = "client";
5680
readonly statusCode = 415;
5781
readonly $frameworkError = true;
82+
constructor() {
83+
super({ name: "UnsupportedMediaTypeException", $fault: "client" });
84+
Object.setPrototypeOf(this, UnsupportedMediaTypeException.prototype);
85+
}
5886
}
5987

60-
export class NotAcceptableException implements SmithyException {
88+
export class NotAcceptableException extends SmithyException {
6189
readonly name = "NotAcceptableException";
6290
readonly $fault = "client";
6391
readonly statusCode = 406;
6492
readonly $frameworkError = true;
93+
constructor() {
94+
super({ name: "NotAcceptableException", $fault: "client" });
95+
Object.setPrototypeOf(this, NotAcceptableException.prototype);
96+
}
6597
}

smithy-typescript-ssdk-libs/server-common/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ export * from "./errors";
1919
export * from "./validation";
2020

2121
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
22-
import { SmithyException } from "@aws-sdk/smithy-client";
2322
import { SerdeContext } from "@aws-sdk/types";
2423

24+
import { SmithyException } from "./errors";
25+
2526
export type Operation<I, O, Context = {}> = (input: I, context: Context) => Promise<O>;
2627

2728
export type OperationInput<T> = T extends Operation<infer I, any, any> ? I : never;

smithy-typescript-ssdk-libs/server-common/src/validation/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
import { SmithyException } from "@aws-sdk/smithy-client";
16+
import { SmithyException } from "../errors";
1717

1818
export * from "./validators";
1919

smithy-typescript-ssdk-libs/yarn.lock

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
# yarn lockfile v1
33

44

5-
"@aws-sdk/[email protected]":
6-
version "3.40.0"
7-
resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-stack/-/middleware-stack-3.40.0.tgz#5aa614e49a4fc76cc63986fb45302f7afab6db87"
8-
integrity sha512-hby9HvESUYJxpdALX+6Dn2LPmS5jtMVurGB/+j3MWOvIcDYB4bcSXgVRvXzYnTKwbSupIdbX9zOE2ZAx2SJpUQ==
9-
dependencies:
10-
tslib "^2.3.0"
11-
125
"@aws-sdk/[email protected]":
136
version "3.40.0"
147
resolved "https://registry.yarnpkg.com/@aws-sdk/protocol-http/-/protocol-http-3.40.0.tgz#ce6c7170a59e0a0eb63df5cd7cec87fe05bae680"
@@ -17,15 +10,6 @@
1710
"@aws-sdk/types" "3.40.0"
1811
tslib "^2.3.0"
1912

20-
"@aws-sdk/[email protected]":
21-
version "3.41.0"
22-
resolved "https://registry.yarnpkg.com/@aws-sdk/smithy-client/-/smithy-client-3.41.0.tgz#61154b4813a01dc079e7083805a20e1bc05d3199"
23-
integrity sha512-ldhS0Pf3v6yHCd//kk5DvKcdyeUkKEwxNDRanAp+ekTW68J3XcYgKaPC9sNDhVTDH1zrywTvtEz5zWHEvXjQow==
24-
dependencies:
25-
"@aws-sdk/middleware-stack" "3.40.0"
26-
"@aws-sdk/types" "3.40.0"
27-
tslib "^2.3.0"
28-
2913
"@aws-sdk/[email protected]":
3014
version "3.40.0"
3115
resolved "https://registry.yarnpkg.com/@aws-sdk/types/-/types-3.40.0.tgz#a9d7926fcb9b699bc46be975033559d2293e60d1"

0 commit comments

Comments
 (0)