@databricks/sdk-core 0.34.0 → 0.35.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.
Files changed (135) hide show
  1. package/dist/apierror/apierror.d.ts +52 -49
  2. package/dist/apierror/apierror.d.ts.map +1 -1
  3. package/dist/apierror/apierror.js +124 -172
  4. package/dist/apierror/apierror.js.map +1 -1
  5. package/dist/apierror/codes/codes.d.ts +113 -113
  6. package/dist/apierror/codes/codes.d.ts.map +1 -1
  7. package/dist/apierror/codes/codes.js +24 -115
  8. package/dist/apierror/codes/codes.js.map +1 -1
  9. package/dist/apierror/codes/index.d.ts +2 -7
  10. package/dist/apierror/codes/index.js +3 -7
  11. package/dist/apierror/details.d.ts +104 -101
  12. package/dist/apierror/details.d.ts.map +1 -1
  13. package/dist/apierror/details.js +151 -226
  14. package/dist/apierror/details.js.map +1 -1
  15. package/dist/apierror/index.d.ts +3 -8
  16. package/dist/apierror/index.js +3 -7
  17. package/dist/clientinfo/agent.d.ts +6 -3
  18. package/dist/clientinfo/agent.d.ts.map +1 -1
  19. package/dist/clientinfo/agent.js +134 -112
  20. package/dist/clientinfo/agent.js.map +1 -1
  21. package/dist/clientinfo/base.d.ts +13 -15
  22. package/dist/clientinfo/base.d.ts.map +1 -1
  23. package/dist/clientinfo/base.js +50 -50
  24. package/dist/clientinfo/base.js.map +1 -1
  25. package/dist/clientinfo/clientinfo.d.ts +40 -38
  26. package/dist/clientinfo/clientinfo.d.ts.map +1 -1
  27. package/dist/clientinfo/clientinfo.js +78 -88
  28. package/dist/clientinfo/clientinfo.js.map +1 -1
  29. package/dist/clientinfo/default.browser.d.ts +6 -10
  30. package/dist/clientinfo/default.browser.d.ts.map +1 -1
  31. package/dist/clientinfo/default.browser.js +24 -16
  32. package/dist/clientinfo/default.browser.js.map +1 -1
  33. package/dist/clientinfo/default.d.ts +8 -4
  34. package/dist/clientinfo/default.d.ts.map +1 -1
  35. package/dist/clientinfo/default.js +157 -102
  36. package/dist/clientinfo/default.js.map +1 -1
  37. package/dist/clientinfo/index.browser.d.ts +4 -5
  38. package/dist/clientinfo/index.browser.js +5 -4
  39. package/dist/clientinfo/index.d.ts +4 -5
  40. package/dist/clientinfo/index.js +5 -4
  41. package/dist/clientinfo/meta-harness.d.ts +6 -3
  42. package/dist/clientinfo/meta-harness.d.ts.map +1 -1
  43. package/dist/clientinfo/meta-harness.js +30 -46
  44. package/dist/clientinfo/meta-harness.js.map +1 -1
  45. package/dist/http/http.d.ts +25 -22
  46. package/dist/http/http.d.ts.map +1 -1
  47. package/dist/http/http.js +24 -34
  48. package/dist/http/http.js.map +1 -1
  49. package/dist/http/index.d.ts +2 -8
  50. package/dist/http/index.js +3 -7
  51. package/dist/index.d.ts +1 -6
  52. package/dist/index.js +7 -5
  53. package/dist/index.js.map +1 -1
  54. package/dist/logger/index.d.ts +2 -8
  55. package/dist/logger/index.js +3 -7
  56. package/dist/logger/logger.d.ts +26 -23
  57. package/dist/logger/logger.d.ts.map +1 -1
  58. package/dist/logger/logger.js +46 -60
  59. package/dist/logger/logger.js.map +1 -1
  60. package/dist/ops/execute.d.ts +7 -3
  61. package/dist/ops/execute.d.ts.map +1 -1
  62. package/dist/ops/execute.js +55 -67
  63. package/dist/ops/execute.js.map +1 -1
  64. package/dist/ops/index.d.ts +5 -12
  65. package/dist/ops/index.js +4 -9
  66. package/dist/ops/limiter.d.ts +5 -2
  67. package/dist/ops/limiter.d.ts.map +1 -1
  68. package/dist/ops/limiter.js +0 -2
  69. package/dist/ops/options.d.ts +23 -19
  70. package/dist/ops/options.d.ts.map +1 -1
  71. package/dist/ops/options.js +0 -2
  72. package/dist/ops/retrier.d.ts +34 -31
  73. package/dist/ops/retrier.d.ts.map +1 -1
  74. package/dist/ops/retrier.js +55 -66
  75. package/dist/ops/retrier.js.map +1 -1
  76. package/dist/package.js +6 -0
  77. package/dist/package.js.map +1 -0
  78. package/dist/profiles/errors.d.ts +7 -4
  79. package/dist/profiles/errors.d.ts.map +1 -1
  80. package/dist/profiles/errors.js +16 -17
  81. package/dist/profiles/errors.js.map +1 -1
  82. package/dist/profiles/index.browser.d.ts +4 -10
  83. package/dist/profiles/index.browser.js +4 -8
  84. package/dist/profiles/index.d.ts +5 -15
  85. package/dist/profiles/index.js +5 -13
  86. package/dist/profiles/ini.d.ts +6 -3
  87. package/dist/profiles/ini.d.ts.map +1 -1
  88. package/dist/profiles/ini.js +60 -108
  89. package/dist/profiles/ini.js.map +1 -1
  90. package/dist/profiles/profile.d.ts +66 -67
  91. package/dist/profiles/profile.d.ts.map +1 -1
  92. package/dist/profiles/profile.js +89 -84
  93. package/dist/profiles/profile.js.map +1 -1
  94. package/dist/profiles/resolve.d.ts +8 -9
  95. package/dist/profiles/resolve.d.ts.map +1 -1
  96. package/dist/profiles/resolve.js +140 -185
  97. package/dist/profiles/resolve.js.map +1 -1
  98. package/dist/profiles/secret.d.ts +15 -12
  99. package/dist/profiles/secret.d.ts.map +1 -1
  100. package/dist/profiles/secret.js +38 -35
  101. package/dist/profiles/secret.js.map +1 -1
  102. package/dist/wkt/fieldmask.d.ts +23 -20
  103. package/dist/wkt/fieldmask.d.ts.map +1 -1
  104. package/dist/wkt/fieldmask.js +53 -62
  105. package/dist/wkt/fieldmask.js.map +1 -1
  106. package/dist/wkt/index.d.ts +3 -4
  107. package/dist/wkt/index.js +3 -2
  108. package/dist/wkt/value.d.ts +6 -3
  109. package/dist/wkt/value.d.ts.map +1 -1
  110. package/dist/wkt/value.js +0 -2
  111. package/package.json +2 -2
  112. package/dist/apierror/codes/index.d.ts.map +0 -1
  113. package/dist/apierror/codes/index.js.map +0 -1
  114. package/dist/apierror/index.d.ts.map +0 -1
  115. package/dist/apierror/index.js.map +0 -1
  116. package/dist/clientinfo/index.browser.d.ts.map +0 -1
  117. package/dist/clientinfo/index.browser.js.map +0 -1
  118. package/dist/clientinfo/index.d.ts.map +0 -1
  119. package/dist/clientinfo/index.js.map +0 -1
  120. package/dist/http/index.d.ts.map +0 -1
  121. package/dist/http/index.js.map +0 -1
  122. package/dist/index.d.ts.map +0 -1
  123. package/dist/logger/index.d.ts.map +0 -1
  124. package/dist/logger/index.js.map +0 -1
  125. package/dist/ops/index.d.ts.map +0 -1
  126. package/dist/ops/index.js.map +0 -1
  127. package/dist/ops/limiter.js.map +0 -1
  128. package/dist/ops/options.js.map +0 -1
  129. package/dist/profiles/index.browser.d.ts.map +0 -1
  130. package/dist/profiles/index.browser.js.map +0 -1
  131. package/dist/profiles/index.d.ts.map +0 -1
  132. package/dist/profiles/index.js.map +0 -1
  133. package/dist/wkt/index.d.ts.map +0 -1
  134. package/dist/wkt/index.js.map +0 -1
  135. package/dist/wkt/value.js.map +0 -1
@@ -1,54 +1,57 @@
1
- import { Code } from './codes';
2
- import type { ErrorDetails } from './details';
1
+ import { Code } from "./codes/codes.js";
2
+ import { ErrorDetails } from "./details.js";
3
+
4
+ //#region src/apierror/apierror.d.ts
3
5
  interface ApiErrorOptions {
4
- code: Code;
5
- message: string;
6
- details: ErrorDetails;
7
- httpStatusCode?: number | undefined;
8
- httpHeader?: Headers | undefined;
9
- httpBody?: Uint8Array | undefined;
10
- cause?: unknown;
6
+ code: Code;
7
+ message: string;
8
+ details: ErrorDetails;
9
+ httpStatusCode?: number | undefined;
10
+ httpHeader?: Headers | undefined;
11
+ httpBody?: Uint8Array | undefined;
12
+ cause?: unknown;
11
13
  }
12
14
  /** ApiError is a transport-agnostic error representing a Databricks API error. */
13
- export declare class ApiError extends Error {
14
- /**
15
- * The error code of the error.
16
- */
17
- readonly code: Code;
18
- /**
19
- * The structured error details of the error. This is left empty if the
20
- * error response is not a standard Databricks API error.
21
- */
22
- readonly details: ErrorDetails;
23
- private readonly httpErr?;
24
- /**
25
- * Do not use this constructor directly. Use {@link ApiError.fromHttpError}
26
- * instead. This constructor is only meant for internal and testing use.
27
- * TODO: Make this constructor private.
28
- *
29
- * @private
30
- */
31
- constructor(options: ApiErrorOptions);
32
- /**
33
- * Returns the ApiError's HTTP status code. If the ApiError is not an HTTP
34
- * error, returns -1.
35
- */
36
- get httpStatusCode(): number;
37
- /**
38
- * Returns the ApiError's HTTP headers. If the ApiError is not an HTTP
39
- * error, returns undefined.
40
- */
41
- get httpHeader(): Headers | undefined;
42
- /**
43
- * Returns the ApiError's HTTP body. If the ApiError is not an HTTP error,
44
- * returns undefined.
45
- */
46
- get httpBody(): Uint8Array | undefined;
47
- /**
48
- * Parses an HTTP error response into an ApiError. Returns undefined if the
49
- * status code is 2xx.
50
- */
51
- static fromHttpError(statusCode: number, header: Headers | undefined, body: Uint8Array | undefined): ApiError | undefined;
15
+ declare class ApiError extends Error {
16
+ /**
17
+ * The error code of the error.
18
+ */
19
+ readonly code: Code;
20
+ /**
21
+ * The structured error details of the error. This is left empty if the
22
+ * error response is not a standard Databricks API error.
23
+ */
24
+ readonly details: ErrorDetails;
25
+ private readonly httpErr?;
26
+ /**
27
+ * Do not use this constructor directly. Use {@link ApiError.fromHttpError}
28
+ * instead. This constructor is only meant for internal and testing use.
29
+ * TODO: Make this constructor private.
30
+ *
31
+ * @private
32
+ */
33
+ constructor(options: ApiErrorOptions);
34
+ /**
35
+ * Returns the ApiError's HTTP status code. If the ApiError is not an HTTP
36
+ * error, returns -1.
37
+ */
38
+ get httpStatusCode(): number;
39
+ /**
40
+ * Returns the ApiError's HTTP headers. If the ApiError is not an HTTP
41
+ * error, returns undefined.
42
+ */
43
+ get httpHeader(): Headers | undefined;
44
+ /**
45
+ * Returns the ApiError's HTTP body. If the ApiError is not an HTTP error,
46
+ * returns undefined.
47
+ */
48
+ get httpBody(): Uint8Array | undefined;
49
+ /**
50
+ * Parses an HTTP error response into an ApiError. Returns undefined if the
51
+ * status code is 2xx.
52
+ */
53
+ static fromHttpError(statusCode: number, header: Headers | undefined, body: Uint8Array | undefined): ApiError | undefined;
52
54
  }
53
- export {};
55
+ //#endregion
56
+ export { ApiError };
54
57
  //# sourceMappingURL=apierror.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apierror.d.ts","sourceRoot":"","sources":["../../src/apierror/apierror.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AA8B5C,UAAU,eAAe;IACvB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,YAAY,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,kFAAkF;AAClF,qBAAa,QAAS,SAAQ,KAAK;IACjC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAEpB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAG/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAIvB;IAEF;;;;;;OAMG;gBACS,OAAO,EAAE,eAAe;IAcpC;;;OAGG;IACH,IAAI,cAAc,IAAI,MAAM,CAK3B;IAED;;;OAGG;IACH,IAAI,UAAU,IAAI,OAAO,GAAG,SAAS,CAKpC;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,UAAU,GAAG,SAAS,CAKrC;IAED;;;OAGG;IACH,MAAM,CAAC,aAAa,CAClB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,GAAG,SAAS,EAC3B,IAAI,EAAE,UAAU,GAAG,SAAS,GAC3B,QAAQ,GAAG,SAAS;CAqFxB"}
1
+ {"version":3,"file":"apierror.d.ts","names":[],"sources":["../../src/apierror/apierror.ts"],"mappings":";;;;UAiCU,eAAA;EACR,IAAA,EAAM,IAAA;EACN,OAAA;EACA,OAAA,EAAS,YAAA;EACT,cAAA;EACA,UAAA,GAAa,OAAA;EACb,QAAA,GAAW,UAAA;EACX,KAAA;AAAA;;cAIW,QAAA,SAAiB,KAAA;EAV5B;;;EAAA,SAcS,IAAA,EAAM,IAAA;EAZN;;;;EAAA,SAkBA,OAAA,EAAS,YAAA;EAAA,iBAGD,OAAA;EAjBjB;;;AAIF;;;;cA0Bc,OAAA,EAAS,eAAA;EAAA;;;;EAAA,IAkBjB,cAAA,CAAA;EAqCD;;;;EAAA,IA1BC,UAAA,CAAA,GAAc,OAAA;EAnDT;;;;EAAA,IA8DL,QAAA,CAAA,GAAY,UAAA;;;;;SAWT,aAAA,CACL,UAAA,UACA,MAAA,EAAQ,OAAA,cACR,IAAA,EAAM,UAAA,eACL,QAAA;AAAA"}
@@ -1,176 +1,128 @@
1
- import { z } from 'zod';
2
- import { Code } from './codes';
3
- import { parseErrorDetails } from './details';
4
- // Reusable schema fragment for nullish string fields.
5
- const nullishString = z
6
- .string()
7
- .nullish()
8
- .transform(v => v ?? '');
9
- // Zod schema for parsing the JSON error response body. The schema is lenient
10
- // to handle the various Databricks API error formats (standard, legacy, SCIM).
1
+ import { Code } from "./codes/codes.js";
2
+ import { parseErrorDetails } from "./details.js";
3
+ import { z } from "zod";
4
+
5
+ //#region src/apierror/apierror.ts
6
+ const nullishString = z.string().nullish().transform((v) => v ?? "");
11
7
  const errorResponseSchema = z.object({
12
- message: nullishString,
13
- details: z
14
- .array(z.unknown())
15
- .nullish()
16
- .transform(v => v ?? []),
17
- // Some Databricks APIs incorrectly return the HTTP status code as an
18
- // integer rather than the actual error code as a string.
19
- error_code: z.unknown().optional(),
20
- // Legacy Databricks APIs (e.g. version 1.2 and earlier) used "error"
21
- // instead of "message".
22
- error: nullishString,
23
- // SCIM error fields (RFC7644 section 3.7.3).
24
- // The "status" field is intentionally omitted; it duplicates HTTP status.
25
- detail: nullishString,
26
- scimType: nullishString,
8
+ message: nullishString,
9
+ details: z.array(z.unknown()).nullish().transform((v) => v ?? []),
10
+ error_code: z.unknown().optional(),
11
+ error: nullishString,
12
+ detail: nullishString,
13
+ scimType: nullishString
27
14
  });
28
15
  /** ApiError is a transport-agnostic error representing a Databricks API error. */
29
- export class ApiError extends Error {
30
- /**
31
- * The error code of the error.
32
- */
33
- code;
34
- /**
35
- * The structured error details of the error. This is left empty if the
36
- * error response is not a standard Databricks API error.
37
- */
38
- details;
39
- // The raw HTTP error details, undefined if this is not an HTTP error.
40
- httpErr;
41
- /**
42
- * Do not use this constructor directly. Use {@link ApiError.fromHttpError}
43
- * instead. This constructor is only meant for internal and testing use.
44
- * TODO: Make this constructor private.
45
- *
46
- * @private
47
- */
48
- constructor(options) {
49
- super(options.message, { cause: options.cause });
50
- this.name = 'ApiError';
51
- this.code = options.code;
52
- this.details = options.details;
53
- if (options.httpStatusCode !== undefined) {
54
- this.httpErr = {
55
- statusCode: options.httpStatusCode,
56
- header: options.httpHeader,
57
- body: options.httpBody,
58
- };
59
- }
60
- }
61
- /**
62
- * Returns the ApiError's HTTP status code. If the ApiError is not an HTTP
63
- * error, returns -1.
64
- */
65
- get httpStatusCode() {
66
- if (this.httpErr === undefined) {
67
- return -1;
68
- }
69
- return this.httpErr.statusCode;
70
- }
71
- /**
72
- * Returns the ApiError's HTTP headers. If the ApiError is not an HTTP
73
- * error, returns undefined.
74
- */
75
- get httpHeader() {
76
- if (this.httpErr === undefined) {
77
- return undefined;
78
- }
79
- return this.httpErr.header;
80
- }
81
- /**
82
- * Returns the ApiError's HTTP body. If the ApiError is not an HTTP error,
83
- * returns undefined.
84
- */
85
- get httpBody() {
86
- if (this.httpErr === undefined) {
87
- return undefined;
88
- }
89
- return this.httpErr.body;
90
- }
91
- /**
92
- * Parses an HTTP error response into an ApiError. Returns undefined if the
93
- * status code is 2xx.
94
- */
95
- static fromHttpError(statusCode, header, body) {
96
- if (statusCode >= 200 && statusCode < 300) {
97
- return undefined;
98
- }
99
- const emptyDetails = { unknownDetails: [] };
100
- if (body === undefined || body.length === 0) {
101
- return new ApiError({
102
- code: Code.UNKNOWN,
103
- message: '',
104
- details: emptyDetails,
105
- httpStatusCode: statusCode,
106
- httpHeader: header,
107
- httpBody: body,
108
- });
109
- }
110
- // Decode the body to a string for JSON parsing.
111
- let parsed;
112
- try {
113
- parsed = JSON.parse(new TextDecoder().decode(body));
114
- }
115
- catch (e) {
116
- // The JSON error is simply swallowed, this typically happens when the
117
- // error does not come directly from a Databricks API. A typical example
118
- // is when the error is returned by a proxy.
119
- return new ApiError({
120
- code: Code.UNKNOWN,
121
- message: '',
122
- details: emptyDetails,
123
- httpStatusCode: statusCode,
124
- httpHeader: header,
125
- httpBody: body,
126
- cause: e instanceof Error ? e : undefined,
127
- });
128
- }
129
- const result = errorResponseSchema.safeParse(parsed);
130
- if (!result.success) {
131
- return new ApiError({
132
- code: Code.UNKNOWN,
133
- message: '',
134
- details: emptyDetails,
135
- httpStatusCode: statusCode,
136
- httpHeader: header,
137
- httpBody: body,
138
- cause: result.error,
139
- });
140
- }
141
- const errResp = result.data;
142
- // code carries the error_code string verbatim: a canonical code (e.g.
143
- // "NOT_FOUND") matches a named Code member, while a Databricks
144
- // product-specific code (e.g. "CATALOG_DOES_NOT_EXIST") is an open Code
145
- // value. It is Code.UNKNOWN when the response carries no string error_code
146
- // (missing or an integer); the HTTP status is never used to infer a code,
147
- // since it may not reflect the true error semantic, so callers fall back to
148
- // httpStatusCode.
149
- const code = typeof errResp.error_code === 'string' && errResp.error_code !== ''
150
- ? errResp.error_code
151
- : Code.UNKNOWN;
152
- // Determine the error message from available fields.
153
- let errorMessage = '';
154
- if (errResp.message !== '') {
155
- errorMessage = errResp.message;
156
- }
157
- else if (errResp.error !== '') {
158
- errorMessage = errResp.error;
159
- }
160
- else if (errResp.detail !== '') {
161
- errorMessage = errResp.detail;
162
- }
163
- else if (errResp.scimType !== '') {
164
- errorMessage = errResp.scimType;
165
- }
166
- return new ApiError({
167
- code,
168
- message: errorMessage,
169
- details: parseErrorDetails(errResp.details),
170
- httpStatusCode: statusCode,
171
- httpHeader: header,
172
- httpBody: body,
173
- });
174
- }
175
- }
16
+ var ApiError = class ApiError extends Error {
17
+ /**
18
+ * The error code of the error.
19
+ */
20
+ code;
21
+ /**
22
+ * The structured error details of the error. This is left empty if the
23
+ * error response is not a standard Databricks API error.
24
+ */
25
+ details;
26
+ httpErr;
27
+ /**
28
+ * Do not use this constructor directly. Use {@link ApiError.fromHttpError}
29
+ * instead. This constructor is only meant for internal and testing use.
30
+ * TODO: Make this constructor private.
31
+ *
32
+ * @private
33
+ */
34
+ constructor(options) {
35
+ super(options.message, { cause: options.cause });
36
+ this.name = "ApiError";
37
+ this.code = options.code;
38
+ this.details = options.details;
39
+ if (options.httpStatusCode !== void 0) this.httpErr = {
40
+ statusCode: options.httpStatusCode,
41
+ header: options.httpHeader,
42
+ body: options.httpBody
43
+ };
44
+ }
45
+ /**
46
+ * Returns the ApiError's HTTP status code. If the ApiError is not an HTTP
47
+ * error, returns -1.
48
+ */
49
+ get httpStatusCode() {
50
+ if (this.httpErr === void 0) return -1;
51
+ return this.httpErr.statusCode;
52
+ }
53
+ /**
54
+ * Returns the ApiError's HTTP headers. If the ApiError is not an HTTP
55
+ * error, returns undefined.
56
+ */
57
+ get httpHeader() {
58
+ if (this.httpErr === void 0) return;
59
+ return this.httpErr.header;
60
+ }
61
+ /**
62
+ * Returns the ApiError's HTTP body. If the ApiError is not an HTTP error,
63
+ * returns undefined.
64
+ */
65
+ get httpBody() {
66
+ if (this.httpErr === void 0) return;
67
+ return this.httpErr.body;
68
+ }
69
+ /**
70
+ * Parses an HTTP error response into an ApiError. Returns undefined if the
71
+ * status code is 2xx.
72
+ */
73
+ static fromHttpError(statusCode, header, body) {
74
+ if (statusCode >= 200 && statusCode < 300) return;
75
+ const emptyDetails = { unknownDetails: [] };
76
+ if (body === void 0 || body.length === 0) return new ApiError({
77
+ code: Code.UNKNOWN,
78
+ message: "",
79
+ details: emptyDetails,
80
+ httpStatusCode: statusCode,
81
+ httpHeader: header,
82
+ httpBody: body
83
+ });
84
+ let parsed;
85
+ try {
86
+ parsed = JSON.parse(new TextDecoder().decode(body));
87
+ } catch (e) {
88
+ return new ApiError({
89
+ code: Code.UNKNOWN,
90
+ message: "",
91
+ details: emptyDetails,
92
+ httpStatusCode: statusCode,
93
+ httpHeader: header,
94
+ httpBody: body,
95
+ cause: e instanceof Error ? e : void 0
96
+ });
97
+ }
98
+ const result = errorResponseSchema.safeParse(parsed);
99
+ if (!result.success) return new ApiError({
100
+ code: Code.UNKNOWN,
101
+ message: "",
102
+ details: emptyDetails,
103
+ httpStatusCode: statusCode,
104
+ httpHeader: header,
105
+ httpBody: body,
106
+ cause: result.error
107
+ });
108
+ const errResp = result.data;
109
+ const code = typeof errResp.error_code === "string" && errResp.error_code !== "" ? errResp.error_code : Code.UNKNOWN;
110
+ let errorMessage = "";
111
+ if (errResp.message !== "") errorMessage = errResp.message;
112
+ else if (errResp.error !== "") errorMessage = errResp.error;
113
+ else if (errResp.detail !== "") errorMessage = errResp.detail;
114
+ else if (errResp.scimType !== "") errorMessage = errResp.scimType;
115
+ return new ApiError({
116
+ code,
117
+ message: errorMessage,
118
+ details: parseErrorDetails(errResp.details),
119
+ httpStatusCode: statusCode,
120
+ httpHeader: header,
121
+ httpBody: body
122
+ });
123
+ }
124
+ };
125
+
126
+ //#endregion
127
+ export { ApiError };
176
128
  //# sourceMappingURL=apierror.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"apierror.js","sourceRoot":"","sources":["../../src/apierror/apierror.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAC,iBAAiB,EAAC,MAAM,WAAW,CAAC;AAE5C,sDAAsD;AACtD,MAAM,aAAa,GAAG,CAAC;KACpB,MAAM,EAAE;KACR,OAAO,EAAE;KACT,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAE3B,6EAA6E;AAC7E,+E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AAE,EAAE,CAAC;YAChC,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;QAC/B,CAAC;aAAM,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACjC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;QAChC,CAAC;aAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,EAAE,EAAE,CAAC;YACnC,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,CAAC;QAED,OAAO,IAAI,QAAQ,CAAC;YAClB,IAAI;YACJ,OAAO,EAAE,YAAY;YACrB,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC;YAC3C,cAAc,EAAE,UAAU;YAC1B,UAAU,EAAE,MAAM;YAClB,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;IACL,CAAC;CACF"}
1
+ {"version":3,"file":"apierror.js","names":[],"sources":["../../src/apierror/apierror.ts"],"sourcesContent":["import {z} from 'zod';\n\nimport {Code} from './codes';\nimport type {ErrorDetails} from './details';\nimport {parseErrorDetails} from './details';\n\n// Reusable schema fragment for nullish string fields.\nconst nullishString = z\n .string()\n .nullish()\n .transform(v => v ?? '');\n\n// Zod schema for parsing the JSON error response body. The schema is lenient\n// to handle the various Databricks API error formats (standard, legacy, SCIM).\nconst errorResponseSchema = z.object({\n message: nullishString,\n details: z\n .array(z.unknown())\n .nullish()\n .transform(v => v ?? []),\n // Some Databricks APIs incorrectly return the HTTP status code as an\n // integer rather than the actual error code as a string.\n error_code: z.unknown().optional(),\n // Legacy Databricks APIs (e.g. version 1.2 and earlier) used \"error\"\n // instead of \"message\".\n error: nullishString,\n // SCIM error fields (RFC7644 section 3.7.3).\n // The \"status\" field is intentionally omitted; it duplicates HTTP status.\n detail: nullishString,\n scimType: nullishString,\n});\n\n// Constructor options for ApiError.\ninterface ApiErrorOptions {\n code: Code;\n message: string;\n details: ErrorDetails;\n httpStatusCode?: number | undefined;\n httpHeader?: Headers | undefined;\n httpBody?: Uint8Array | undefined;\n cause?: unknown;\n}\n\n/** ApiError is a transport-agnostic error representing a Databricks API error. */\nexport class ApiError extends Error {\n /**\n * The error code of the error.\n */\n readonly code: Code;\n\n /**\n * The structured error details of the error. This is left empty if the\n * error response is not a standard Databricks API error.\n */\n readonly details: ErrorDetails;\n\n // The raw HTTP error details, undefined if this is not an HTTP error.\n private readonly httpErr?: {\n readonly statusCode: number;\n readonly header: Headers | undefined;\n readonly body: Uint8Array | undefined;\n };\n\n /**\n * Do not use this constructor directly. Use {@link ApiError.fromHttpError}\n * instead. This constructor is only meant for internal and testing use.\n * TODO: Make this constructor private.\n *\n * @private\n */\n constructor(options: ApiErrorOptions) {\n super(options.message, {cause: options.cause});\n this.name = 'ApiError';\n this.code = options.code;\n this.details = options.details;\n if (options.httpStatusCode !== undefined) {\n this.httpErr = {\n statusCode: options.httpStatusCode,\n header: options.httpHeader,\n body: options.httpBody,\n };\n }\n }\n\n /**\n * Returns the ApiError's HTTP status code. If the ApiError is not an HTTP\n * error, returns -1.\n */\n get httpStatusCode(): number {\n if (this.httpErr === undefined) {\n return -1;\n }\n return this.httpErr.statusCode;\n }\n\n /**\n * Returns the ApiError's HTTP headers. If the ApiError is not an HTTP\n * error, returns undefined.\n */\n get httpHeader(): Headers | undefined {\n if (this.httpErr === undefined) {\n return undefined;\n }\n return this.httpErr.header;\n }\n\n /**\n * Returns the ApiError's HTTP body. If the ApiError is not an HTTP error,\n * returns undefined.\n */\n get httpBody(): Uint8Array | undefined {\n if (this.httpErr === undefined) {\n return undefined;\n }\n return this.httpErr.body;\n }\n\n /**\n * Parses an HTTP error response into an ApiError. Returns undefined if the\n * status code is 2xx.\n */\n static fromHttpError(\n statusCode: number,\n header: Headers | undefined,\n body: Uint8Array | undefined\n ): ApiError | undefined {\n if (statusCode >= 200 && statusCode < 300) {\n return undefined;\n }\n\n const emptyDetails: ErrorDetails = {unknownDetails: []};\n\n if (body === undefined || body.length === 0) {\n return new ApiError({\n code: Code.UNKNOWN,\n message: '',\n details: emptyDetails,\n httpStatusCode: statusCode,\n httpHeader: header,\n httpBody: body,\n });\n }\n\n // Decode the body to a string for JSON parsing.\n let parsed: unknown;\n try {\n parsed = JSON.parse(new TextDecoder().decode(body));\n } catch (e: unknown) {\n // The JSON error is simply swallowed, this typically happens when the\n // error does not come directly from a Databricks API. A typical example\n // is when the error is returned by a proxy.\n return new ApiError({\n code: Code.UNKNOWN,\n message: '',\n details: emptyDetails,\n httpStatusCode: statusCode,\n httpHeader: header,\n httpBody: body,\n cause: e instanceof Error ? e : undefined,\n });\n }\n\n const result = errorResponseSchema.safeParse(parsed);\n if (!result.success) {\n return new ApiError({\n code: Code.UNKNOWN,\n message: '',\n details: emptyDetails,\n httpStatusCode: statusCode,\n httpHeader: header,\n httpBody: body,\n cause: result.error,\n });\n }\n\n const errResp = result.data;\n\n // code carries the error_code string verbatim: a canonical code (e.g.\n // \"NOT_FOUND\") matches a named Code member, while a Databricks\n // product-specific code (e.g. \"CATALOG_DOES_NOT_EXIST\") is an open Code\n // value. It is Code.UNKNOWN when the response carries no string error_code\n // (missing or an integer); the HTTP status is never used to infer a code,\n // since it may not reflect the true error semantic, so callers fall back to\n // httpStatusCode.\n const code: Code =\n typeof errResp.error_code === 'string' && errResp.error_code !== ''\n ? errResp.error_code\n : Code.UNKNOWN;\n\n // Determine the error message from available fields.\n let errorMessage = '';\n if (errResp.message !== '') {\n errorMessage = errResp.message;\n } else if (errResp.error !== '') {\n errorMessage = errResp.error;\n } else if (errResp.detail !== '') {\n errorMessage = errResp.detail;\n } else if (errResp.scimType !== '') {\n errorMessage = errResp.scimType;\n }\n\n return new ApiError({\n code,\n message: errorMessage,\n details: parseErrorDetails(errResp.details),\n httpStatusCode: statusCode,\n httpHeader: header,\n httpBody: body,\n });\n }\n}\n"],"mappings":";;;;;AAOA,MAAM,gBAAgB,EACnB,QAAQ,CACR,SAAS,CACT,WAAU,MAAK,KAAK,GAAG;AAI1B,MAAM,sBAAsB,EAAE,OAAO;CACnC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