@pexip-engage-public/graphql 1.1.3 → 1.1.4
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/CHANGELOG.md
CHANGED
|
@@ -2,37 +2,21 @@ import { ClientError } from "graphql-request";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { GraphQLErrorCode } from "./graphql-error-codes.js";
|
|
4
4
|
declare const ExtensionSchema: z.ZodUnion<[z.ZodObject<{
|
|
5
|
-
|
|
6
|
-
message: z.ZodString;
|
|
7
|
-
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
message: string;
|
|
9
|
-
}, {
|
|
10
|
-
message: string;
|
|
11
|
-
}>;
|
|
5
|
+
message: z.ZodString;
|
|
12
6
|
/**
|
|
13
7
|
* A `400` response code indicates a malformed request.
|
|
14
8
|
*
|
|
15
9
|
* The request should not be retried without changes.
|
|
16
10
|
*/
|
|
17
|
-
|
|
11
|
+
statusCode: z.ZodLiteral<400>;
|
|
18
12
|
}, "strip", z.ZodTypeAny, {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
http: 400;
|
|
13
|
+
statusCode: 400;
|
|
14
|
+
message: string;
|
|
23
15
|
}, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
http: 400;
|
|
16
|
+
statusCode: 400;
|
|
17
|
+
message: string;
|
|
28
18
|
}>, z.ZodObject<{
|
|
29
|
-
|
|
30
|
-
message: z.ZodString;
|
|
31
|
-
}, "strip", z.ZodTypeAny, {
|
|
32
|
-
message: string;
|
|
33
|
-
}, {
|
|
34
|
-
message: string;
|
|
35
|
-
}>;
|
|
19
|
+
message: z.ZodString;
|
|
36
20
|
/**
|
|
37
21
|
* A `401` response code indicates an unauthorized request.
|
|
38
22
|
*
|
|
@@ -40,169 +24,105 @@ declare const ExtensionSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
40
24
|
*
|
|
41
25
|
* The request should not be retried with the same `Authorization` header value.
|
|
42
26
|
*/
|
|
43
|
-
|
|
27
|
+
statusCode: z.ZodLiteral<401>;
|
|
44
28
|
}, "strip", z.ZodTypeAny, {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
http: 401;
|
|
29
|
+
statusCode: 401;
|
|
30
|
+
message: string;
|
|
49
31
|
}, {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
http: 401;
|
|
32
|
+
statusCode: 401;
|
|
33
|
+
message: string;
|
|
54
34
|
}>, z.ZodObject<{
|
|
55
|
-
|
|
56
|
-
message: z.ZodString;
|
|
57
|
-
}, "strip", z.ZodTypeAny, {
|
|
58
|
-
message: string;
|
|
59
|
-
}, {
|
|
60
|
-
message: string;
|
|
61
|
-
}>;
|
|
35
|
+
message: z.ZodString;
|
|
62
36
|
/**
|
|
63
37
|
* A `403` response code indicates a forbidden request.
|
|
64
38
|
*
|
|
65
39
|
* The provided `Authorization` header value is valid but the request is prohibited due to other permission restrictions (e.g., missing scopes or organizational settings).
|
|
66
40
|
*/
|
|
67
|
-
|
|
41
|
+
statusCode: z.ZodLiteral<403>;
|
|
68
42
|
}, "strip", z.ZodTypeAny, {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
http: 403;
|
|
43
|
+
statusCode: 403;
|
|
44
|
+
message: string;
|
|
73
45
|
}, {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
http: 403;
|
|
46
|
+
statusCode: 403;
|
|
47
|
+
message: string;
|
|
78
48
|
}>, z.ZodObject<{
|
|
79
|
-
|
|
80
|
-
message: z.ZodString;
|
|
81
|
-
}, "strip", z.ZodTypeAny, {
|
|
82
|
-
message: string;
|
|
83
|
-
}, {
|
|
84
|
-
message: string;
|
|
85
|
-
}>;
|
|
49
|
+
message: z.ZodString;
|
|
86
50
|
/**
|
|
87
51
|
* A `404` response code indicates a resource that cannot be found.
|
|
88
52
|
*
|
|
89
53
|
* This response code will be returned in case of a non-existent URL being used or a non-existent resource ID being used in a valid URL structure.
|
|
90
54
|
*/
|
|
91
|
-
|
|
55
|
+
statusCode: z.ZodLiteral<404>;
|
|
92
56
|
}, "strip", z.ZodTypeAny, {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
http: 404;
|
|
57
|
+
statusCode: 404;
|
|
58
|
+
message: string;
|
|
97
59
|
}, {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
101
|
-
http: 404;
|
|
60
|
+
statusCode: 404;
|
|
61
|
+
message: string;
|
|
102
62
|
}>, z.ZodObject<{
|
|
103
|
-
|
|
104
|
-
message: z.ZodString;
|
|
105
|
-
}, "strip", z.ZodTypeAny, {
|
|
106
|
-
message: string;
|
|
107
|
-
}, {
|
|
108
|
-
message: string;
|
|
109
|
-
}>;
|
|
63
|
+
message: z.ZodString;
|
|
110
64
|
/**
|
|
111
65
|
* A `405` response code indicates that the HTTP method being used is not supported for the target URL.
|
|
112
66
|
*
|
|
113
67
|
* The request should not be retried without changes.
|
|
114
68
|
*/
|
|
115
|
-
|
|
69
|
+
statusCode: z.ZodLiteral<405>;
|
|
116
70
|
}, "strip", z.ZodTypeAny, {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
http: 405;
|
|
71
|
+
statusCode: 405;
|
|
72
|
+
message: string;
|
|
121
73
|
}, {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
125
|
-
http: 405;
|
|
74
|
+
statusCode: 405;
|
|
75
|
+
message: string;
|
|
126
76
|
}>, z.ZodObject<{
|
|
127
|
-
|
|
128
|
-
message: z.ZodString;
|
|
129
|
-
}, "strip", z.ZodTypeAny, {
|
|
130
|
-
message: string;
|
|
131
|
-
}, {
|
|
132
|
-
message: string;
|
|
133
|
-
}>;
|
|
77
|
+
message: z.ZodString;
|
|
134
78
|
/**
|
|
135
79
|
* A `409` response code indicates a conflict, caused by concurrent operations, that resulted in a situation where the requested operation could not be performed simultaneously with another operation.
|
|
136
80
|
*
|
|
137
81
|
* The request can be retried without changes but will most likely result in another error response code.
|
|
138
82
|
*/
|
|
139
|
-
|
|
83
|
+
statusCode: z.ZodLiteral<409>;
|
|
140
84
|
}, "strip", z.ZodTypeAny, {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
};
|
|
144
|
-
http: 409;
|
|
85
|
+
statusCode: 409;
|
|
86
|
+
message: string;
|
|
145
87
|
}, {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
};
|
|
149
|
-
http: 409;
|
|
88
|
+
statusCode: 409;
|
|
89
|
+
message: string;
|
|
150
90
|
}>, z.ZodObject<{
|
|
151
91
|
code: z.ZodNativeEnum<typeof GraphQLErrorCode>;
|
|
152
|
-
|
|
153
|
-
message: z.ZodString;
|
|
154
|
-
}, "strip", z.ZodTypeAny, {
|
|
155
|
-
message: string;
|
|
156
|
-
}, {
|
|
157
|
-
message: string;
|
|
158
|
-
}>;
|
|
92
|
+
message: z.ZodString;
|
|
159
93
|
/**
|
|
160
94
|
* A `422` response code indicates a failed business validation.
|
|
161
95
|
*
|
|
162
96
|
* More information on the business validation concerned can be found in [Error codes](https://developer.pexipengage.com/topic/topic-error-codes) by looking up the specific error code mentioned in the `errors` array in the response body.
|
|
163
97
|
*/
|
|
164
|
-
|
|
98
|
+
statusCode: z.ZodLiteral<422>;
|
|
165
99
|
type: z.ZodLiteral<"UnprocessableEntity">;
|
|
166
100
|
}, "strip", z.ZodTypeAny, {
|
|
167
101
|
type: "UnprocessableEntity";
|
|
168
102
|
code: GraphQLErrorCode;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
};
|
|
172
|
-
http: 422;
|
|
103
|
+
statusCode: 422;
|
|
104
|
+
message: string;
|
|
173
105
|
}, {
|
|
174
106
|
type: "UnprocessableEntity";
|
|
175
107
|
code: GraphQLErrorCode;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
};
|
|
179
|
-
http: 422;
|
|
108
|
+
statusCode: 422;
|
|
109
|
+
message: string;
|
|
180
110
|
}>, z.ZodObject<{
|
|
181
|
-
|
|
182
|
-
message: z.ZodString;
|
|
183
|
-
}, "strip", z.ZodTypeAny, {
|
|
184
|
-
message: string;
|
|
185
|
-
}, {
|
|
186
|
-
message: string;
|
|
187
|
-
}>;
|
|
111
|
+
message: z.ZodString;
|
|
188
112
|
/** A `429` response code indicates that too many requests were sent in a given amount of time. See [Rate limiting](https://developer.pexipengage.com/topic/topic-rate-limiting). */
|
|
189
|
-
|
|
113
|
+
statusCode: z.ZodLiteral<429>;
|
|
190
114
|
}, "strip", z.ZodTypeAny, {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
};
|
|
194
|
-
http: 429;
|
|
115
|
+
statusCode: 429;
|
|
116
|
+
message: string;
|
|
195
117
|
}, {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
};
|
|
199
|
-
http: 429;
|
|
118
|
+
statusCode: 429;
|
|
119
|
+
message: string;
|
|
200
120
|
}>]>;
|
|
201
121
|
type Extension = z.infer<typeof ExtensionSchema>;
|
|
202
|
-
type
|
|
122
|
+
type StatusCode = Extension["statusCode"];
|
|
203
123
|
type ErrorMap = {
|
|
204
|
-
[key in
|
|
205
|
-
|
|
124
|
+
[key in StatusCode]?: Extract<Extension, {
|
|
125
|
+
statusCode: key;
|
|
206
126
|
}>[];
|
|
207
127
|
};
|
|
208
128
|
export interface GQLError {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-error-handler.d.ts","sourceRoot":"","sources":["../src/graphql-error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,QAAA,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"graphql-error-handler.d.ts","sourceRoot":"","sources":["../src/graphql-error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,QAAA,MAAM,eAAe;;IAGjB;;;;OAIG;;;;;;;;;;IAKH;;;;;;OAMG;;;;;;;;;;IAKH;;;;OAIG;;;;;;;;;;IAKH;;;;OAIG;;;;;;;;;;IAKH;;;;OAIG;;;;;;;;;;IAKH;;;;OAIG;;;;;;;;;;;IAMH;;;;OAIG;;;;;;;;;;;;;;;IAUH,oLAAoL;;;;;;;;IAGtL,CAAC;AAEH,KAAK,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACjD,KAAK,UAAU,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;AAC1C,KAAK,QAAQ,GAAG;KAAG,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE;QAAE,UAAU,EAAE,GAAG,CAAA;KAAE,CAAC,EAAE;CAAE,CAAC;AAEpF,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO;;;;;;;;;;EAmC5C"}
|
|
@@ -3,16 +3,16 @@ import { z } from "zod";
|
|
|
3
3
|
import { GraphQLErrorCode } from "./graphql-error-codes.js";
|
|
4
4
|
const ExtensionSchema = z.union([
|
|
5
5
|
z.object({
|
|
6
|
-
|
|
6
|
+
message: z.string(),
|
|
7
7
|
/**
|
|
8
8
|
* A `400` response code indicates a malformed request.
|
|
9
9
|
*
|
|
10
10
|
* The request should not be retried without changes.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
statusCode: z.literal(400),
|
|
13
13
|
}),
|
|
14
14
|
z.object({
|
|
15
|
-
|
|
15
|
+
message: z.string(),
|
|
16
16
|
/**
|
|
17
17
|
* A `401` response code indicates an unauthorized request.
|
|
18
18
|
*
|
|
@@ -20,53 +20,53 @@ const ExtensionSchema = z.union([
|
|
|
20
20
|
*
|
|
21
21
|
* The request should not be retried with the same `Authorization` header value.
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
statusCode: z.literal(401),
|
|
24
24
|
}),
|
|
25
25
|
z.object({
|
|
26
|
-
|
|
26
|
+
message: z.string(),
|
|
27
27
|
/**
|
|
28
28
|
* A `403` response code indicates a forbidden request.
|
|
29
29
|
*
|
|
30
30
|
* The provided `Authorization` header value is valid but the request is prohibited due to other permission restrictions (e.g., missing scopes or organizational settings).
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
statusCode: z.literal(403),
|
|
33
33
|
}),
|
|
34
34
|
z.object({
|
|
35
|
-
|
|
35
|
+
message: z.string(),
|
|
36
36
|
/**
|
|
37
37
|
* A `404` response code indicates a resource that cannot be found.
|
|
38
38
|
*
|
|
39
39
|
* This response code will be returned in case of a non-existent URL being used or a non-existent resource ID being used in a valid URL structure.
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
statusCode: z.literal(404),
|
|
42
42
|
}),
|
|
43
43
|
z.object({
|
|
44
|
-
|
|
44
|
+
message: z.string(),
|
|
45
45
|
/**
|
|
46
46
|
* A `405` response code indicates that the HTTP method being used is not supported for the target URL.
|
|
47
47
|
*
|
|
48
48
|
* The request should not be retried without changes.
|
|
49
49
|
*/
|
|
50
|
-
|
|
50
|
+
statusCode: z.literal(405),
|
|
51
51
|
}),
|
|
52
52
|
z.object({
|
|
53
|
-
|
|
53
|
+
message: z.string(),
|
|
54
54
|
/**
|
|
55
55
|
* A `409` response code indicates a conflict, caused by concurrent operations, that resulted in a situation where the requested operation could not be performed simultaneously with another operation.
|
|
56
56
|
*
|
|
57
57
|
* The request can be retried without changes but will most likely result in another error response code.
|
|
58
58
|
*/
|
|
59
|
-
|
|
59
|
+
statusCode: z.literal(409),
|
|
60
60
|
}),
|
|
61
61
|
z.object({
|
|
62
62
|
code: z.nativeEnum(GraphQLErrorCode),
|
|
63
|
-
|
|
63
|
+
message: z.string(),
|
|
64
64
|
/**
|
|
65
65
|
* A `422` response code indicates a failed business validation.
|
|
66
66
|
*
|
|
67
67
|
* More information on the business validation concerned can be found in [Error codes](https://developer.pexipengage.com/topic/topic-error-codes) by looking up the specific error code mentioned in the `errors` array in the response body.
|
|
68
68
|
*/
|
|
69
|
-
|
|
69
|
+
statusCode: z.literal(422),
|
|
70
70
|
type: z.literal("UnprocessableEntity"),
|
|
71
71
|
// type: "UnprocessableEntity",
|
|
72
72
|
// exception: {
|
|
@@ -74,25 +74,28 @@ const ExtensionSchema = z.union([
|
|
|
74
74
|
// },
|
|
75
75
|
}),
|
|
76
76
|
z.object({
|
|
77
|
-
|
|
77
|
+
message: z.string(),
|
|
78
78
|
/** A `429` response code indicates that too many requests were sent in a given amount of time. See [Rate limiting](https://developer.pexipengage.com/topic/topic-rate-limiting). */
|
|
79
|
-
|
|
79
|
+
statusCode: z.literal(429),
|
|
80
80
|
}),
|
|
81
81
|
]);
|
|
82
82
|
export function handleGQLError(error) {
|
|
83
83
|
if (error instanceof ClientError) {
|
|
84
84
|
try {
|
|
85
|
-
const extensions = error.response.errors?.map((err) => ExtensionSchema.safeParse(
|
|
85
|
+
const extensions = error.response.errors?.map((err) => ExtensionSchema.safeParse({
|
|
86
|
+
...err.extensions,
|
|
87
|
+
message: err.message,
|
|
88
|
+
}).data);
|
|
86
89
|
const map = {};
|
|
87
90
|
const errorMap = extensions?.reduce((acc, extension) => {
|
|
88
91
|
if (!extension)
|
|
89
92
|
return acc;
|
|
90
|
-
const currentEntry = acc[extension.
|
|
93
|
+
const currentEntry = acc[extension.statusCode];
|
|
91
94
|
if (currentEntry) {
|
|
92
95
|
currentEntry.push(extension);
|
|
93
96
|
}
|
|
94
97
|
else {
|
|
95
|
-
acc[extension.
|
|
98
|
+
acc[extension.statusCode] = [extension];
|
|
96
99
|
}
|
|
97
100
|
return acc;
|
|
98
101
|
}, map) ?? map;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-error-handler.js","sourceRoot":"","sources":["../src/graphql-error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC;IAC9B,CAAC,CAAC,MAAM,CAAC;QACP,
|
|
1
|
+
{"version":3,"file":"graphql-error-handler.js","sourceRoot":"","sources":["../src/graphql-error-handler.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pexip-engage-public/graphql",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"homepage": "https://github.com/skedify/frontend-mono/tree/develop/packages/graphql#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/skedify/frontend-mono/issues"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"CHANGELOG.md"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"gql.tada": "^1.8.
|
|
36
|
+
"gql.tada": "^1.8.11",
|
|
37
37
|
"graphql": "^16.11.0",
|
|
38
38
|
"graphql-request": "^7.2.0",
|
|
39
39
|
"lz-string": "^1.5.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@graphql-inspector/cli": "^5.0.8",
|
|
47
47
|
"typescript": "^5.8.3",
|
|
48
48
|
"@pexip-engage/tsconfig": "0.1.1",
|
|
49
|
-
"eslint-config-pexip-engage": "1.1.
|
|
49
|
+
"eslint-config-pexip-engage": "1.1.24"
|
|
50
50
|
},
|
|
51
51
|
"volta": {
|
|
52
52
|
"extends": "../../package.json"
|
|
@@ -5,16 +5,16 @@ import { GraphQLErrorCode } from "./graphql-error-codes.js";
|
|
|
5
5
|
|
|
6
6
|
const ExtensionSchema = z.union([
|
|
7
7
|
z.object({
|
|
8
|
-
|
|
8
|
+
message: z.string(),
|
|
9
9
|
/**
|
|
10
10
|
* A `400` response code indicates a malformed request.
|
|
11
11
|
*
|
|
12
12
|
* The request should not be retried without changes.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
statusCode: z.literal(400),
|
|
15
15
|
}),
|
|
16
16
|
z.object({
|
|
17
|
-
|
|
17
|
+
message: z.string(),
|
|
18
18
|
/**
|
|
19
19
|
* A `401` response code indicates an unauthorized request.
|
|
20
20
|
*
|
|
@@ -22,53 +22,53 @@ const ExtensionSchema = z.union([
|
|
|
22
22
|
*
|
|
23
23
|
* The request should not be retried with the same `Authorization` header value.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
statusCode: z.literal(401),
|
|
26
26
|
}),
|
|
27
27
|
z.object({
|
|
28
|
-
|
|
28
|
+
message: z.string(),
|
|
29
29
|
/**
|
|
30
30
|
* A `403` response code indicates a forbidden request.
|
|
31
31
|
*
|
|
32
32
|
* The provided `Authorization` header value is valid but the request is prohibited due to other permission restrictions (e.g., missing scopes or organizational settings).
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
statusCode: z.literal(403),
|
|
35
35
|
}),
|
|
36
36
|
z.object({
|
|
37
|
-
|
|
37
|
+
message: z.string(),
|
|
38
38
|
/**
|
|
39
39
|
* A `404` response code indicates a resource that cannot be found.
|
|
40
40
|
*
|
|
41
41
|
* This response code will be returned in case of a non-existent URL being used or a non-existent resource ID being used in a valid URL structure.
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
statusCode: z.literal(404),
|
|
44
44
|
}),
|
|
45
45
|
z.object({
|
|
46
|
-
|
|
46
|
+
message: z.string(),
|
|
47
47
|
/**
|
|
48
48
|
* A `405` response code indicates that the HTTP method being used is not supported for the target URL.
|
|
49
49
|
*
|
|
50
50
|
* The request should not be retried without changes.
|
|
51
51
|
*/
|
|
52
|
-
|
|
52
|
+
statusCode: z.literal(405),
|
|
53
53
|
}),
|
|
54
54
|
z.object({
|
|
55
|
-
|
|
55
|
+
message: z.string(),
|
|
56
56
|
/**
|
|
57
57
|
* A `409` response code indicates a conflict, caused by concurrent operations, that resulted in a situation where the requested operation could not be performed simultaneously with another operation.
|
|
58
58
|
*
|
|
59
59
|
* The request can be retried without changes but will most likely result in another error response code.
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
statusCode: z.literal(409),
|
|
62
62
|
}),
|
|
63
63
|
z.object({
|
|
64
64
|
code: z.nativeEnum(GraphQLErrorCode),
|
|
65
|
-
|
|
65
|
+
message: z.string(),
|
|
66
66
|
/**
|
|
67
67
|
* A `422` response code indicates a failed business validation.
|
|
68
68
|
*
|
|
69
69
|
* More information on the business validation concerned can be found in [Error codes](https://developer.pexipengage.com/topic/topic-error-codes) by looking up the specific error code mentioned in the `errors` array in the response body.
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
statusCode: z.literal(422),
|
|
72
72
|
type: z.literal("UnprocessableEntity"),
|
|
73
73
|
// type: "UnprocessableEntity",
|
|
74
74
|
// exception: {
|
|
@@ -76,15 +76,15 @@ const ExtensionSchema = z.union([
|
|
|
76
76
|
// },
|
|
77
77
|
}),
|
|
78
78
|
z.object({
|
|
79
|
-
|
|
79
|
+
message: z.string(),
|
|
80
80
|
/** A `429` response code indicates that too many requests were sent in a given amount of time. See [Rate limiting](https://developer.pexipengage.com/topic/topic-rate-limiting). */
|
|
81
|
-
|
|
81
|
+
statusCode: z.literal(429),
|
|
82
82
|
}),
|
|
83
83
|
]);
|
|
84
84
|
|
|
85
85
|
type Extension = z.infer<typeof ExtensionSchema>;
|
|
86
|
-
type
|
|
87
|
-
type ErrorMap = { [key in
|
|
86
|
+
type StatusCode = Extension["statusCode"];
|
|
87
|
+
type ErrorMap = { [key in StatusCode]?: Extract<Extension, { statusCode: key }>[] };
|
|
88
88
|
|
|
89
89
|
export interface GQLError {
|
|
90
90
|
type: "GQL";
|
|
@@ -96,19 +96,23 @@ export function handleGQLError(error: unknown) {
|
|
|
96
96
|
if (error instanceof ClientError) {
|
|
97
97
|
try {
|
|
98
98
|
const extensions = error.response.errors?.map(
|
|
99
|
-
(err) =>
|
|
99
|
+
(err) =>
|
|
100
|
+
ExtensionSchema.safeParse({
|
|
101
|
+
...err.extensions,
|
|
102
|
+
message: err.message,
|
|
103
|
+
}).data,
|
|
100
104
|
);
|
|
101
105
|
|
|
102
106
|
const map: ErrorMap = {};
|
|
103
107
|
const errorMap =
|
|
104
108
|
extensions?.reduce((acc, extension) => {
|
|
105
109
|
if (!extension) return acc;
|
|
106
|
-
const currentEntry = acc[extension.
|
|
110
|
+
const currentEntry = acc[extension.statusCode];
|
|
107
111
|
|
|
108
112
|
if (currentEntry) {
|
|
109
113
|
currentEntry.push(extension as any);
|
|
110
114
|
} else {
|
|
111
|
-
acc[extension.
|
|
115
|
+
acc[extension.statusCode] = [extension as any];
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
return acc;
|