@supernova-studio/client 0.54.33 → 0.54.35

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.54.33",
3
+ "version": "0.54.35",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -1,18 +1,49 @@
1
+ import { SupernovaExceptionType } from "@supernova-studio/model";
2
+
1
3
  export type RequestExecutorErrorType = "ServerError" | "ResponseParsingError";
4
+ export type RequestEexecutorServerErrorCode = SupernovaExceptionType | undefined;
2
5
 
3
6
  export class RequestExecutorError extends Error {
7
+ readonly type: RequestExecutorErrorType;
8
+ readonly errorCode: RequestEexecutorServerErrorCode;
9
+
10
+ static tryParseErrorCode(body: string) {
11
+ try {
12
+ const errorObj = JSON.parse(body);
13
+ if (errorObj && typeof errorObj.errorCode === "string") {
14
+ return errorObj.errorCode;
15
+ }
16
+ return null;
17
+ } catch (e) {
18
+ return null;
19
+ }
20
+ }
21
+
4
22
  static serverError(endpoint: string, status: number, bodyText: string) {
5
- return new RequestExecutorError("ServerError", `Endpoint ${endpoint} returned ${status}\n${bodyText}`);
23
+ return new RequestExecutorError(
24
+ "ServerError",
25
+ `Endpoint ${endpoint} returned ${status}\n${bodyText}`,
26
+ this.tryParseErrorCode(bodyText)
27
+ );
6
28
  }
7
29
 
8
30
  static responseParsingError(endpoint: string, cause: Error) {
9
- return new RequestExecutorError("ResponseParsingError", `Endpoint ${endpoint} returned incompatible JSON`, cause);
31
+ return new RequestExecutorError(
32
+ "ResponseParsingError",
33
+ `Endpoint ${endpoint} returned incompatible JSON`,
34
+ undefined,
35
+ cause
36
+ );
10
37
  }
11
38
 
12
- readonly type: RequestExecutorErrorType;
13
-
14
- private constructor(type: RequestExecutorErrorType, message: string, cause?: unknown) {
39
+ private constructor(
40
+ type: RequestExecutorErrorType,
41
+ message: string,
42
+ errorCode: RequestEexecutorServerErrorCode | undefined,
43
+ cause?: unknown
44
+ ) {
15
45
  super(`${type}: ${message}`, { cause });
16
46
  this.type = type;
47
+ this.errorCode = errorCode;
17
48
  }
18
49
  }