@algolia/client-common 5.0.0-alpha.33 → 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 +17 -5
- package/dist/client-common.esm.node.js +17 -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
|
@@ -317,8 +317,8 @@ class RetryError extends ErrorWithStackTrace {
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
class ApiError extends ErrorWithStackTrace {
|
|
320
|
-
constructor(message, status, stackTrace) {
|
|
321
|
-
super(message, stackTrace,
|
|
320
|
+
constructor(message, status, stackTrace, name = 'ApiError') {
|
|
321
|
+
super(message, stackTrace, name);
|
|
322
322
|
_defineProperty(this, "status", void 0);
|
|
323
323
|
this.status = status;
|
|
324
324
|
}
|
|
@@ -330,6 +330,14 @@ class DeserializationError extends AlgoliaError {
|
|
|
330
330
|
this.response = response;
|
|
331
331
|
}
|
|
332
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
|
+
}
|
|
333
341
|
|
|
334
342
|
function shuffle(array) {
|
|
335
343
|
const shuffledArray = array;
|
|
@@ -388,13 +396,16 @@ function deserializeFailure({
|
|
|
388
396
|
content,
|
|
389
397
|
status
|
|
390
398
|
}, stackFrame) {
|
|
391
|
-
let message = content;
|
|
392
399
|
try {
|
|
393
|
-
|
|
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);
|
|
394
405
|
} catch (e) {
|
|
395
406
|
// ..
|
|
396
407
|
}
|
|
397
|
-
return new ApiError(
|
|
408
|
+
return new ApiError(content, status, stackFrame);
|
|
398
409
|
}
|
|
399
410
|
|
|
400
411
|
function isNetworkError({
|
|
@@ -715,6 +726,7 @@ exports.DEFAULT_READ_TIMEOUT_NODE = DEFAULT_READ_TIMEOUT_NODE;
|
|
|
715
726
|
exports.DEFAULT_WRITE_TIMEOUT_BROWSER = DEFAULT_WRITE_TIMEOUT_BROWSER;
|
|
716
727
|
exports.DEFAULT_WRITE_TIMEOUT_NODE = DEFAULT_WRITE_TIMEOUT_NODE;
|
|
717
728
|
exports.DeserializationError = DeserializationError;
|
|
729
|
+
exports.DetailedApiError = DetailedApiError;
|
|
718
730
|
exports.ErrorWithStackTrace = ErrorWithStackTrace;
|
|
719
731
|
exports.RetryError = RetryError;
|
|
720
732
|
exports.createAlgoliaAgent = createAlgoliaAgent;
|
|
@@ -313,8 +313,8 @@ class RetryError extends ErrorWithStackTrace {
|
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
class ApiError extends ErrorWithStackTrace {
|
|
316
|
-
constructor(message, status, stackTrace) {
|
|
317
|
-
super(message, stackTrace,
|
|
316
|
+
constructor(message, status, stackTrace, name = 'ApiError') {
|
|
317
|
+
super(message, stackTrace, name);
|
|
318
318
|
_defineProperty(this, "status", void 0);
|
|
319
319
|
this.status = status;
|
|
320
320
|
}
|
|
@@ -326,6 +326,14 @@ class DeserializationError extends AlgoliaError {
|
|
|
326
326
|
this.response = response;
|
|
327
327
|
}
|
|
328
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
|
+
}
|
|
329
337
|
|
|
330
338
|
function shuffle(array) {
|
|
331
339
|
const shuffledArray = array;
|
|
@@ -384,13 +392,16 @@ function deserializeFailure({
|
|
|
384
392
|
content,
|
|
385
393
|
status
|
|
386
394
|
}, stackFrame) {
|
|
387
|
-
let message = content;
|
|
388
395
|
try {
|
|
389
|
-
|
|
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);
|
|
390
401
|
} catch (e) {
|
|
391
402
|
// ..
|
|
392
403
|
}
|
|
393
|
-
return new ApiError(
|
|
404
|
+
return new ApiError(content, status, stackFrame);
|
|
394
405
|
}
|
|
395
406
|
|
|
396
407
|
function isNetworkError({
|
|
@@ -702,4 +713,4 @@ const DEFAULT_CONNECT_TIMEOUT_NODE = 2000;
|
|
|
702
713
|
const DEFAULT_READ_TIMEOUT_NODE = 5000;
|
|
703
714
|
const DEFAULT_WRITE_TIMEOUT_NODE = 30000;
|
|
704
715
|
|
|
705
|
-
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,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,C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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
|
}
|