@databricks/sdk-core 0.34.0 → 0.36.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/dist/apierror/apierror.d.ts +52 -49
- package/dist/apierror/apierror.d.ts.map +1 -1
- package/dist/apierror/apierror.js +124 -172
- package/dist/apierror/apierror.js.map +1 -1
- package/dist/apierror/codes/codes.d.ts +113 -113
- package/dist/apierror/codes/codes.d.ts.map +1 -1
- package/dist/apierror/codes/codes.js +24 -115
- package/dist/apierror/codes/codes.js.map +1 -1
- package/dist/apierror/codes/index.d.ts +2 -7
- package/dist/apierror/codes/index.js +3 -7
- package/dist/apierror/details.d.ts +104 -101
- package/dist/apierror/details.d.ts.map +1 -1
- package/dist/apierror/details.js +151 -226
- package/dist/apierror/details.js.map +1 -1
- package/dist/apierror/index.d.ts +3 -8
- package/dist/apierror/index.js +3 -7
- package/dist/clientinfo/agent.d.ts +6 -3
- package/dist/clientinfo/agent.d.ts.map +1 -1
- package/dist/clientinfo/agent.js +134 -112
- package/dist/clientinfo/agent.js.map +1 -1
- package/dist/clientinfo/base.d.ts +13 -15
- package/dist/clientinfo/base.d.ts.map +1 -1
- package/dist/clientinfo/base.js +50 -50
- package/dist/clientinfo/base.js.map +1 -1
- package/dist/clientinfo/clientinfo.d.ts +40 -38
- package/dist/clientinfo/clientinfo.d.ts.map +1 -1
- package/dist/clientinfo/clientinfo.js +78 -88
- package/dist/clientinfo/clientinfo.js.map +1 -1
- package/dist/clientinfo/default.browser.d.ts +6 -10
- package/dist/clientinfo/default.browser.d.ts.map +1 -1
- package/dist/clientinfo/default.browser.js +24 -16
- package/dist/clientinfo/default.browser.js.map +1 -1
- package/dist/clientinfo/default.d.ts +8 -4
- package/dist/clientinfo/default.d.ts.map +1 -1
- package/dist/clientinfo/default.js +157 -102
- package/dist/clientinfo/default.js.map +1 -1
- package/dist/clientinfo/index.browser.d.ts +4 -5
- package/dist/clientinfo/index.browser.js +5 -4
- package/dist/clientinfo/index.d.ts +4 -5
- package/dist/clientinfo/index.js +5 -4
- package/dist/clientinfo/meta-harness.d.ts +6 -3
- package/dist/clientinfo/meta-harness.d.ts.map +1 -1
- package/dist/clientinfo/meta-harness.js +30 -46
- package/dist/clientinfo/meta-harness.js.map +1 -1
- package/dist/http/http.d.ts +25 -22
- package/dist/http/http.d.ts.map +1 -1
- package/dist/http/http.js +24 -34
- package/dist/http/http.js.map +1 -1
- package/dist/http/index.d.ts +2 -8
- package/dist/http/index.js +3 -7
- package/dist/index.d.ts +1 -6
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/logger/index.d.ts +2 -8
- package/dist/logger/index.js +3 -7
- package/dist/logger/logger.d.ts +26 -23
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +46 -60
- package/dist/logger/logger.js.map +1 -1
- package/dist/ops/execute.d.ts +7 -3
- package/dist/ops/execute.d.ts.map +1 -1
- package/dist/ops/execute.js +55 -67
- package/dist/ops/execute.js.map +1 -1
- package/dist/ops/index.d.ts +5 -12
- package/dist/ops/index.js +4 -9
- package/dist/ops/limiter.d.ts +5 -2
- package/dist/ops/limiter.d.ts.map +1 -1
- package/dist/ops/limiter.js +0 -2
- package/dist/ops/options.d.ts +23 -19
- package/dist/ops/options.d.ts.map +1 -1
- package/dist/ops/options.js +0 -2
- package/dist/ops/retrier.d.ts +34 -31
- package/dist/ops/retrier.d.ts.map +1 -1
- package/dist/ops/retrier.js +55 -66
- package/dist/ops/retrier.js.map +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/profiles/errors.d.ts +7 -4
- package/dist/profiles/errors.d.ts.map +1 -1
- package/dist/profiles/errors.js +16 -17
- package/dist/profiles/errors.js.map +1 -1
- package/dist/profiles/index.browser.d.ts +4 -10
- package/dist/profiles/index.browser.js +4 -8
- package/dist/profiles/index.d.ts +5 -15
- package/dist/profiles/index.js +5 -13
- package/dist/profiles/ini.d.ts +6 -3
- package/dist/profiles/ini.d.ts.map +1 -1
- package/dist/profiles/ini.js +60 -108
- package/dist/profiles/ini.js.map +1 -1
- package/dist/profiles/profile.d.ts +66 -67
- package/dist/profiles/profile.d.ts.map +1 -1
- package/dist/profiles/profile.js +89 -84
- package/dist/profiles/profile.js.map +1 -1
- package/dist/profiles/resolve.d.ts +8 -9
- package/dist/profiles/resolve.d.ts.map +1 -1
- package/dist/profiles/resolve.js +140 -185
- package/dist/profiles/resolve.js.map +1 -1
- package/dist/profiles/secret.d.ts +15 -12
- package/dist/profiles/secret.d.ts.map +1 -1
- package/dist/profiles/secret.js +38 -35
- package/dist/profiles/secret.js.map +1 -1
- package/dist/wkt/fieldmask.d.ts +23 -20
- package/dist/wkt/fieldmask.d.ts.map +1 -1
- package/dist/wkt/fieldmask.js +53 -62
- package/dist/wkt/fieldmask.js.map +1 -1
- package/dist/wkt/index.d.ts +3 -4
- package/dist/wkt/index.js +3 -2
- package/dist/wkt/value.d.ts +6 -3
- package/dist/wkt/value.d.ts.map +1 -1
- package/dist/wkt/value.js +0 -2
- package/package.json +2 -2
- package/dist/apierror/codes/index.d.ts.map +0 -1
- package/dist/apierror/codes/index.js.map +0 -1
- package/dist/apierror/index.d.ts.map +0 -1
- package/dist/apierror/index.js.map +0 -1
- package/dist/clientinfo/index.browser.d.ts.map +0 -1
- package/dist/clientinfo/index.browser.js.map +0 -1
- package/dist/clientinfo/index.d.ts.map +0 -1
- package/dist/clientinfo/index.js.map +0 -1
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/index.js.map +0 -1
- package/dist/ops/index.d.ts.map +0 -1
- package/dist/ops/index.js.map +0 -1
- package/dist/ops/limiter.js.map +0 -1
- package/dist/ops/options.js.map +0 -1
- package/dist/profiles/index.browser.d.ts.map +0 -1
- package/dist/profiles/index.browser.js.map +0 -1
- package/dist/profiles/index.d.ts.map +0 -1
- package/dist/profiles/index.js.map +0 -1
- package/dist/wkt/index.d.ts.map +0 -1
- package/dist/wkt/index.js.map +0 -1
- package/dist/wkt/value.js.map +0 -1
|
@@ -1,54 +1,57 @@
|
|
|
1
|
-
import { Code } from
|
|
2
|
-
import
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
+
//#endregion
|
|
56
|
+
export { ApiError };
|
|
54
57
|
//# sourceMappingURL=apierror.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apierror.d.ts","
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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","
|
|
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,KAA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