File tree Expand file tree Collapse file tree 3 files changed +61
-17
lines changed
clients/algoliasearch-client-javascript
packages/client-common/src/transporter Expand file tree Collapse file tree 3 files changed +61
-17
lines changed Original file line number Diff line number Diff line change 2
2
"files" : [
3
3
{
4
4
"path" : " packages/algoliasearch/dist/algoliasearch.umd.js" ,
5
- "maxSize" : " 7.80KB "
5
+ "maxSize" : " 8.00KB "
6
6
},
7
7
{
8
8
"path" : " packages/algoliasearch/dist/lite/lite.umd.js" ,
9
- "maxSize" : " 3.50KB "
9
+ "maxSize" : " 3.70KB "
10
10
},
11
11
{
12
12
"path" : " packages/client-abtesting/dist/client-abtesting.umd.js" ,
13
- "maxSize" : " 3.65KB "
13
+ "maxSize" : " 3.85KB "
14
14
},
15
15
{
16
16
"path" : " packages/client-analytics/dist/client-analytics.umd.js" ,
17
- "maxSize" : " 4.30KB "
17
+ "maxSize" : " 4.50KB "
18
18
},
19
19
{
20
20
"path" : " packages/client-insights/dist/client-insights.umd.js" ,
21
- "maxSize" : " 3.50KB "
21
+ "maxSize" : " 3.65KB "
22
22
},
23
23
{
24
24
"path" : " packages/client-personalization/dist/client-personalization.umd.js" ,
25
- "maxSize" : " 3.60KB "
25
+ "maxSize" : " 3.80KB "
26
26
},
27
27
{
28
28
"path" : " packages/client-query-suggestions/dist/client-query-suggestions.umd.js" ,
29
- "maxSize" : " 3.70KB "
29
+ "maxSize" : " 3.85KB "
30
30
},
31
31
{
32
32
"path" : " packages/client-search/dist/client-search.umd.js" ,
33
- "maxSize" : " 6.35KB "
33
+ "maxSize" : " 6.55KB "
34
34
},
35
35
{
36
36
"path" : " packages/ingestion/dist/ingestion.umd.js" ,
37
- "maxSize" : " 3.50KB "
37
+ "maxSize" : " 4.30KB "
38
38
},
39
39
{
40
40
"path" : " packages/predict/dist/predict.umd.js" ,
41
- "maxSize" : " 3.50KB "
41
+ "maxSize" : " 4.20KB "
42
42
},
43
43
{
44
44
"path" : " packages/recommend/dist/recommend.umd.js" ,
45
- "maxSize" : " 3.50KB "
45
+ "maxSize" : " 3.70KB "
46
46
}
47
47
]
48
48
}
Original file line number Diff line number Diff line change @@ -35,8 +35,13 @@ export class RetryError extends ErrorWithStackTrace {
35
35
export class ApiError extends ErrorWithStackTrace {
36
36
status : number ;
37
37
38
- constructor ( message : string , status : number , stackTrace : StackFrame [ ] ) {
39
- super ( message , stackTrace , 'ApiError' ) ;
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
+ }
Original file line number Diff line number Diff line change @@ -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
- message = JSON . parse ( content ) . message ;
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 ( message , status , stackFrame ) ;
126
+ return new ApiError ( content , status , stackFrame ) ;
119
127
}
You can’t perform that action at this time.
0 commit comments