@algolia/client-common 5.0.0-alpha.32 → 5.0.0-alpha.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.
- package/dist/client-common.cjs.js +32 -5
- package/dist/client-common.esm.node.js +32 -6
- package/dist/src/transporter/errors.d.ts +18 -1
- package/dist/src/transporter/errors.d.ts.map +1 -1
- package/dist/src/transporter/helpers.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/transporter/errors.ts +38 -2
- package/src/transporter/helpers.ts +12 -4
|
@@ -266,6 +266,7 @@ function createStatefulHost(host, status = 'up') {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
function _defineProperty(obj, key, value) {
|
|
269
|
+
key = _toPropertyKey(key);
|
|
269
270
|
if (key in obj) {
|
|
270
271
|
Object.defineProperty(obj, key, {
|
|
271
272
|
value: value,
|
|
@@ -278,6 +279,20 @@ function _defineProperty(obj, key, value) {
|
|
|
278
279
|
}
|
|
279
280
|
return obj;
|
|
280
281
|
}
|
|
282
|
+
function _toPrimitive(input, hint) {
|
|
283
|
+
if (typeof input !== "object" || input === null) return input;
|
|
284
|
+
var prim = input[Symbol.toPrimitive];
|
|
285
|
+
if (prim !== undefined) {
|
|
286
|
+
var res = prim.call(input, hint || "default");
|
|
287
|
+
if (typeof res !== "object") return res;
|
|
288
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
289
|
+
}
|
|
290
|
+
return (hint === "string" ? String : Number)(input);
|
|
291
|
+
}
|
|
292
|
+
function _toPropertyKey(arg) {
|
|
293
|
+
var key = _toPrimitive(arg, "string");
|
|
294
|
+
return typeof key === "symbol" ? key : String(key);
|
|
295
|
+
}
|
|
281
296
|
|
|
282
297
|
class AlgoliaError extends Error {
|
|
283
298
|
constructor(message, name) {
|
|
@@ -302,8 +317,8 @@ class RetryError extends ErrorWithStackTrace {
|
|
|
302
317
|
}
|
|
303
318
|
}
|
|
304
319
|
class ApiError extends ErrorWithStackTrace {
|
|
305
|
-
constructor(message, status, stackTrace) {
|
|
306
|
-
super(message, stackTrace,
|
|
320
|
+
constructor(message, status, stackTrace, name = 'ApiError') {
|
|
321
|
+
super(message, stackTrace, name);
|
|
307
322
|
_defineProperty(this, "status", void 0);
|
|
308
323
|
this.status = status;
|
|
309
324
|
}
|
|
@@ -315,6 +330,14 @@ class DeserializationError extends AlgoliaError {
|
|
|
315
330
|
this.response = response;
|
|
316
331
|
}
|
|
317
332
|
}
|
|
333
|
+
// DetailedApiError is only used by the ingestion client to return more informative error, other clients will use ApiClient.
|
|
334
|
+
class DetailedApiError extends ApiError {
|
|
335
|
+
constructor(message, status, error, stackTrace) {
|
|
336
|
+
super(message, status, stackTrace, 'DetailedApiError');
|
|
337
|
+
_defineProperty(this, "error", void 0);
|
|
338
|
+
this.error = error;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
318
341
|
|
|
319
342
|
function shuffle(array) {
|
|
320
343
|
const shuffledArray = array;
|
|
@@ -373,13 +396,16 @@ function deserializeFailure({
|
|
|
373
396
|
content,
|
|
374
397
|
status
|
|
375
398
|
}, stackFrame) {
|
|
376
|
-
let message = content;
|
|
377
399
|
try {
|
|
378
|
-
|
|
400
|
+
const parsed = JSON.parse(content);
|
|
401
|
+
if ('error' in parsed) {
|
|
402
|
+
return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);
|
|
403
|
+
}
|
|
404
|
+
return new ApiError(parsed.message, status, stackFrame);
|
|
379
405
|
} catch (e) {
|
|
380
406
|
// ..
|
|
381
407
|
}
|
|
382
|
-
return new ApiError(
|
|
408
|
+
return new ApiError(content, status, stackFrame);
|
|
383
409
|
}
|
|
384
410
|
|
|
385
411
|
function isNetworkError({
|
|
@@ -700,6 +726,7 @@ exports.DEFAULT_READ_TIMEOUT_NODE = DEFAULT_READ_TIMEOUT_NODE;
|
|
|
700
726
|
exports.DEFAULT_WRITE_TIMEOUT_BROWSER = DEFAULT_WRITE_TIMEOUT_BROWSER;
|
|
701
727
|
exports.DEFAULT_WRITE_TIMEOUT_NODE = DEFAULT_WRITE_TIMEOUT_NODE;
|
|
702
728
|
exports.DeserializationError = DeserializationError;
|
|
729
|
+
exports.DetailedApiError = DetailedApiError;
|
|
703
730
|
exports.ErrorWithStackTrace = ErrorWithStackTrace;
|
|
704
731
|
exports.RetryError = RetryError;
|
|
705
732
|
exports.createAlgoliaAgent = createAlgoliaAgent;
|
|
@@ -262,6 +262,7 @@ function createStatefulHost(host, status = 'up') {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
function _defineProperty(obj, key, value) {
|
|
265
|
+
key = _toPropertyKey(key);
|
|
265
266
|
if (key in obj) {
|
|
266
267
|
Object.defineProperty(obj, key, {
|
|
267
268
|
value: value,
|
|
@@ -274,6 +275,20 @@ function _defineProperty(obj, key, value) {
|
|
|
274
275
|
}
|
|
275
276
|
return obj;
|
|
276
277
|
}
|
|
278
|
+
function _toPrimitive(input, hint) {
|
|
279
|
+
if (typeof input !== "object" || input === null) return input;
|
|
280
|
+
var prim = input[Symbol.toPrimitive];
|
|
281
|
+
if (prim !== undefined) {
|
|
282
|
+
var res = prim.call(input, hint || "default");
|
|
283
|
+
if (typeof res !== "object") return res;
|
|
284
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
285
|
+
}
|
|
286
|
+
return (hint === "string" ? String : Number)(input);
|
|
287
|
+
}
|
|
288
|
+
function _toPropertyKey(arg) {
|
|
289
|
+
var key = _toPrimitive(arg, "string");
|
|
290
|
+
return typeof key === "symbol" ? key : String(key);
|
|
291
|
+
}
|
|
277
292
|
|
|
278
293
|
class AlgoliaError extends Error {
|
|
279
294
|
constructor(message, name) {
|
|
@@ -298,8 +313,8 @@ class RetryError extends ErrorWithStackTrace {
|
|
|
298
313
|
}
|
|
299
314
|
}
|
|
300
315
|
class ApiError extends ErrorWithStackTrace {
|
|
301
|
-
constructor(message, status, stackTrace) {
|
|
302
|
-
super(message, stackTrace,
|
|
316
|
+
constructor(message, status, stackTrace, name = 'ApiError') {
|
|
317
|
+
super(message, stackTrace, name);
|
|
303
318
|
_defineProperty(this, "status", void 0);
|
|
304
319
|
this.status = status;
|
|
305
320
|
}
|
|
@@ -311,6 +326,14 @@ class DeserializationError extends AlgoliaError {
|
|
|
311
326
|
this.response = response;
|
|
312
327
|
}
|
|
313
328
|
}
|
|
329
|
+
// DetailedApiError is only used by the ingestion client to return more informative error, other clients will use ApiClient.
|
|
330
|
+
class DetailedApiError extends ApiError {
|
|
331
|
+
constructor(message, status, error, stackTrace) {
|
|
332
|
+
super(message, status, stackTrace, 'DetailedApiError');
|
|
333
|
+
_defineProperty(this, "error", void 0);
|
|
334
|
+
this.error = error;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
314
337
|
|
|
315
338
|
function shuffle(array) {
|
|
316
339
|
const shuffledArray = array;
|
|
@@ -369,13 +392,16 @@ function deserializeFailure({
|
|
|
369
392
|
content,
|
|
370
393
|
status
|
|
371
394
|
}, stackFrame) {
|
|
372
|
-
let message = content;
|
|
373
395
|
try {
|
|
374
|
-
|
|
396
|
+
const parsed = JSON.parse(content);
|
|
397
|
+
if ('error' in parsed) {
|
|
398
|
+
return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);
|
|
399
|
+
}
|
|
400
|
+
return new ApiError(parsed.message, status, stackFrame);
|
|
375
401
|
} catch (e) {
|
|
376
402
|
// ..
|
|
377
403
|
}
|
|
378
|
-
return new ApiError(
|
|
404
|
+
return new ApiError(content, status, stackFrame);
|
|
379
405
|
}
|
|
380
406
|
|
|
381
407
|
function isNetworkError({
|
|
@@ -687,4 +713,4 @@ const DEFAULT_CONNECT_TIMEOUT_NODE = 2000;
|
|
|
687
713
|
const DEFAULT_READ_TIMEOUT_NODE = 5000;
|
|
688
714
|
const DEFAULT_WRITE_TIMEOUT_NODE = 30000;
|
|
689
715
|
|
|
690
|
-
export { AlgoliaError, ApiError, DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_NODE, DeserializationError, ErrorWithStackTrace, RetryError, createAlgoliaAgent, createAuth, createBrowserLocalStorageCache, createEchoRequester, createFallbackableCache, createIterablePromise, createMemoryCache, createNullCache, createStatefulHost, createTransporter, deserializeFailure, deserializeSuccess, getAlgoliaAgent, isNetworkError, isRetryable, isSuccess, serializeData, serializeHeaders, serializeQueryParameters, serializeUrl, shuffle, stackFrameWithoutCredentials, stackTraceWithoutCredentials };
|
|
716
|
+
export { AlgoliaError, ApiError, DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_NODE, DeserializationError, DetailedApiError, ErrorWithStackTrace, RetryError, createAlgoliaAgent, createAuth, createBrowserLocalStorageCache, createEchoRequester, createFallbackableCache, createIterablePromise, createMemoryCache, createNullCache, createStatefulHost, createTransporter, deserializeFailure, deserializeSuccess, getAlgoliaAgent, isNetworkError, isRetryable, isSuccess, serializeData, serializeHeaders, serializeQueryParameters, serializeUrl, shuffle, stackFrameWithoutCredentials, stackTraceWithoutCredentials };
|
|
@@ -12,10 +12,27 @@ export declare class RetryError extends ErrorWithStackTrace {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class ApiError extends ErrorWithStackTrace {
|
|
14
14
|
status: number;
|
|
15
|
-
constructor(message: string, status: number, stackTrace: StackFrame[]);
|
|
15
|
+
constructor(message: string, status: number, stackTrace: StackFrame[], name?: string);
|
|
16
16
|
}
|
|
17
17
|
export declare class DeserializationError extends AlgoliaError {
|
|
18
18
|
response: Response;
|
|
19
19
|
constructor(message: string, response: Response);
|
|
20
20
|
}
|
|
21
|
+
export declare type DetailedErrorWithMessage = {
|
|
22
|
+
message: string;
|
|
23
|
+
label: string;
|
|
24
|
+
};
|
|
25
|
+
export declare type DetailedErrorWithTypeID = {
|
|
26
|
+
id: string;
|
|
27
|
+
type: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
};
|
|
30
|
+
export declare type DetailedError = {
|
|
31
|
+
code: string;
|
|
32
|
+
details?: DetailedErrorWithMessage[] | DetailedErrorWithTypeID[];
|
|
33
|
+
};
|
|
34
|
+
export declare class DetailedApiError extends ApiError {
|
|
35
|
+
error: DetailedError;
|
|
36
|
+
constructor(message: string, status: number, error: DetailedError, stackTrace: StackFrame[]);
|
|
37
|
+
}
|
|
21
38
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/transporter/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAkB;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAO1C;AAED,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,UAAU,EAAE,UAAU,EAAE,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM;CAKpE;AAED,qBAAa,UAAW,SAAQ,mBAAmB;gBACrC,UAAU,EAAE,UAAU,EAAE;CAOrC;AAED,qBAAa,QAAS,SAAQ,mBAAmB;IAC/C,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/transporter/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAkB;gBAElB,OAAO,EA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,MAAM,CAe5E;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,cAAc,GAC7B,MAAM,GAAG,SAAS,CAapB;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,OAAO,EACpB,cAAc,EAAE,OAAO,EACvB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAeT;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAMvE;AAED,wBAAgB,kBAAkB,CAChC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAC7B,UAAU,EAAE,UAAU,EAAE,GACvB,KAAK,CAgBP"}
|
package/package.json
CHANGED
|
@@ -35,8 +35,13 @@ export class RetryError extends ErrorWithStackTrace {
|
|
|
35
35
|
export class ApiError extends ErrorWithStackTrace {
|
|
36
36
|
status: number;
|
|
37
37
|
|
|
38
|
-
constructor(
|
|
39
|
-
|
|
38
|
+
constructor(
|
|
39
|
+
message: string,
|
|
40
|
+
status: number,
|
|
41
|
+
stackTrace: StackFrame[],
|
|
42
|
+
name = 'ApiError'
|
|
43
|
+
) {
|
|
44
|
+
super(message, stackTrace, name);
|
|
40
45
|
this.status = status;
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -49,3 +54,34 @@ export class DeserializationError extends AlgoliaError {
|
|
|
49
54
|
this.response = response;
|
|
50
55
|
}
|
|
51
56
|
}
|
|
57
|
+
|
|
58
|
+
export type DetailedErrorWithMessage = {
|
|
59
|
+
message: string;
|
|
60
|
+
label: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type DetailedErrorWithTypeID = {
|
|
64
|
+
id: string;
|
|
65
|
+
type: string;
|
|
66
|
+
name?: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type DetailedError = {
|
|
70
|
+
code: string;
|
|
71
|
+
details?: DetailedErrorWithMessage[] | DetailedErrorWithTypeID[];
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// DetailedApiError is only used by the ingestion client to return more informative error, other clients will use ApiClient.
|
|
75
|
+
export class DetailedApiError extends ApiError {
|
|
76
|
+
error: DetailedError;
|
|
77
|
+
|
|
78
|
+
constructor(
|
|
79
|
+
message: string,
|
|
80
|
+
status: number,
|
|
81
|
+
error: DetailedError,
|
|
82
|
+
stackTrace: StackFrame[]
|
|
83
|
+
) {
|
|
84
|
+
super(message, status, stackTrace, 'DetailedApiError');
|
|
85
|
+
this.error = error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
StackFrame,
|
|
9
9
|
} from '../types';
|
|
10
10
|
|
|
11
|
-
import { ApiError, DeserializationError } from './errors';
|
|
11
|
+
import { ApiError, DeserializationError, DetailedApiError } from './errors';
|
|
12
12
|
|
|
13
13
|
export function shuffle<TData>(array: TData[]): TData[] {
|
|
14
14
|
const shuffledArray = array;
|
|
@@ -109,11 +109,19 @@ export function deserializeFailure(
|
|
|
109
109
|
{ content, status }: Response,
|
|
110
110
|
stackFrame: StackFrame[]
|
|
111
111
|
): Error {
|
|
112
|
-
let message = content;
|
|
113
112
|
try {
|
|
114
|
-
|
|
113
|
+
const parsed = JSON.parse(content);
|
|
114
|
+
if ('error' in parsed) {
|
|
115
|
+
return new DetailedApiError(
|
|
116
|
+
parsed.message,
|
|
117
|
+
status,
|
|
118
|
+
parsed.error,
|
|
119
|
+
stackFrame
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return new ApiError(parsed.message, status, stackFrame);
|
|
115
123
|
} catch (e) {
|
|
116
124
|
// ..
|
|
117
125
|
}
|
|
118
|
-
return new ApiError(
|
|
126
|
+
return new ApiError(content, status, stackFrame);
|
|
119
127
|
}
|