@kensio/yulin 1.21.33 → 1.21.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,11 @@ export declare function simSdkWireOutputResponse(output: unknown, contentType?:
12
12
  * AWS exception name and the status real AWS answers with, so a handler
13
13
  * catching `ResourceNotFoundException` catches the same thing here as in
14
14
  * production.
15
+ *
16
+ * The body also carries the exception's modelled members, such as the
17
+ * `CancellationReasons` of a DynamoDB `TransactionCanceledException`. The SDK
18
+ * maps those from the body onto the exception it throws, so a member left out
19
+ * here is undefined on the caller's side.
15
20
  */
16
21
  export declare function simSdkWireErrorResponse(error: unknown, contentType?: string): SimSdkWireResponse;
17
22
  /**
@@ -24,6 +24,11 @@ export function simSdkWireOutputResponse(output, contentType = defaultContentTyp
24
24
  * AWS exception name and the status real AWS answers with, so a handler
25
25
  * catching `ResourceNotFoundException` catches the same thing here as in
26
26
  * production.
27
+ *
28
+ * The body also carries the exception's modelled members, such as the
29
+ * `CancellationReasons` of a DynamoDB `TransactionCanceledException`. The SDK
30
+ * maps those from the body onto the exception it throws, so a member left out
31
+ * here is undefined on the caller's side.
27
32
  */
28
33
  export function simSdkWireErrorResponse(error, contentType = defaultContentType) {
29
34
  const errorType = error instanceof Error ? error.name : "InternalFailure";
@@ -35,11 +40,26 @@ export function simSdkWireErrorResponse(error, contentType = defaultContentType)
35
40
  ...Object.fromEntries([["x-amzn-errortype", errorType]]),
36
41
  },
37
42
  body: simSdkWireJsonBody(Object.fromEntries([
43
+ ...errorMembers(error),
38
44
  ["__type", errorType],
39
45
  ["message", message],
40
46
  ])),
41
47
  };
42
48
  }
49
+ /**
50
+ * The modelled members a simulated service error carries.
51
+ *
52
+ * AWS names the members of its exception shapes in PascalCase, as it names
53
+ * the members of every other shape. The lower-case properties of an Error are
54
+ * either JavaScript's own or the simulator's diagnostics, such as the
55
+ * principal an IAM denial names, and none of them is part of the response.
56
+ */
57
+ function errorMembers(error) {
58
+ if (!(error instanceof Error)) {
59
+ return [];
60
+ }
61
+ return Object.entries(error).filter(([name]) => /^[A-Z]/u.test(name));
62
+ }
43
63
  /**
44
64
  * The status a simulated service error is answered with.
45
65
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kensio/yulin",
3
- "version": "1.21.33",
3
+ "version": "1.21.34",
4
4
  "description": "AWS system behaviour simulation for isolated unit testing",
5
5
  "repository": "https://github.com/KensioSoftware/yulin",
6
6
  "homepage": "https://yulinsim.dev/",