@supernova-studio/client 0.54.35 → 0.55.0

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.35",
3
+ "version": "0.55.0",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -6,6 +6,7 @@ export type RequestEexecutorServerErrorCode = SupernovaExceptionType | undefined
6
6
  export class RequestExecutorError extends Error {
7
7
  readonly type: RequestExecutorErrorType;
8
8
  readonly errorCode: RequestEexecutorServerErrorCode;
9
+ readonly serverErrorType: SupernovaExceptionType | undefined;
9
10
 
10
11
  static tryParseErrorCode(body: string) {
11
12
  try {
@@ -19,11 +20,24 @@ export class RequestExecutorError extends Error {
19
20
  }
20
21
  }
21
22
 
23
+ static tryParseServerErrorType(body: string) {
24
+ try {
25
+ const errorObj = JSON.parse(body);
26
+ if (errorObj && typeof errorObj.errorCode === "string") {
27
+ return errorObj.type;
28
+ }
29
+ return null;
30
+ } catch (e) {
31
+ return null;
32
+ }
33
+ }
34
+
22
35
  static serverError(endpoint: string, status: number, bodyText: string) {
23
36
  return new RequestExecutorError(
24
37
  "ServerError",
25
38
  `Endpoint ${endpoint} returned ${status}\n${bodyText}`,
26
- this.tryParseErrorCode(bodyText)
39
+ this.tryParseErrorCode(bodyText),
40
+ this.tryParseServerErrorType(bodyText)
27
41
  );
28
42
  }
29
43
 
@@ -32,6 +46,7 @@ export class RequestExecutorError extends Error {
32
46
  "ResponseParsingError",
33
47
  `Endpoint ${endpoint} returned incompatible JSON`,
34
48
  undefined,
49
+ undefined,
35
50
  cause
36
51
  );
37
52
  }
@@ -40,10 +55,12 @@ export class RequestExecutorError extends Error {
40
55
  type: RequestExecutorErrorType,
41
56
  message: string,
42
57
  errorCode: RequestEexecutorServerErrorCode | undefined,
58
+ serverErrorType?: SupernovaExceptionType | undefined,
43
59
  cause?: unknown
44
60
  ) {
45
61
  super(`${type}: ${message}`, { cause });
46
62
  this.type = type;
47
63
  this.errorCode = errorCode;
64
+ this.serverErrorType = serverErrorType;
48
65
  }
49
66
  }