@trpc/server 11.0.0-rc.435 → 11.0.0-rc.439
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/bundle-analysis.json +49 -48
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/createProxy.js +4 -7
- package/dist/unstable-core-do-not-import/createProxy.mjs +4 -7
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +4 -4
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +4 -4
- package/package.json +3 -3
- package/src/unstable-core-do-not-import/createProxy.ts +1 -5
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +4 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 27.
|
|
2
|
+
"bundleSize": 129192,
|
|
3
|
+
"bundleOrigSize": 178852,
|
|
4
|
+
"bundleReduction": 27.77,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dependents": [
|
|
15
15
|
"/src/unstable-core-do-not-import.ts"
|
|
16
16
|
],
|
|
17
|
-
"percent": 13.
|
|
17
|
+
"percent": 13.22,
|
|
18
18
|
"reduction": 0
|
|
19
19
|
},
|
|
20
20
|
{
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"/src/unstable-core-do-not-import.ts",
|
|
32
32
|
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
33
33
|
],
|
|
34
|
-
"percent": 12.
|
|
34
|
+
"percent": 12.14,
|
|
35
35
|
"reduction": 6.72
|
|
36
36
|
},
|
|
37
37
|
{
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dependents": [
|
|
47
47
|
"/src/adapters/fastify/fastifyTRPCPlugin.ts"
|
|
48
48
|
],
|
|
49
|
-
"percent": 11.
|
|
49
|
+
"percent": 11.05,
|
|
50
50
|
"reduction": 0
|
|
51
51
|
},
|
|
52
52
|
{
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"/src/unstable-core-do-not-import.ts",
|
|
62
62
|
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
63
63
|
],
|
|
64
|
-
"percent": 5.
|
|
64
|
+
"percent": 5.88,
|
|
65
65
|
"reduction": 0
|
|
66
66
|
},
|
|
67
67
|
{
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"/src/unstable-core-do-not-import.ts",
|
|
80
80
|
"/src/unstable-core-do-not-import/initTRPC.ts"
|
|
81
81
|
],
|
|
82
|
-
"percent": 4.
|
|
82
|
+
"percent": 4.94,
|
|
83
83
|
"reduction": 39.72
|
|
84
84
|
},
|
|
85
85
|
{
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"/src/unstable-core-do-not-import.ts",
|
|
95
95
|
"/src/unstable-core-do-not-import/initTRPC.ts"
|
|
96
96
|
],
|
|
97
|
-
"percent": 4.
|
|
97
|
+
"percent": 4.9,
|
|
98
98
|
"reduction": 60.06
|
|
99
99
|
},
|
|
100
100
|
{
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
"dependents": [
|
|
162
162
|
"/src/adapters/next-app-dir.ts"
|
|
163
163
|
],
|
|
164
|
-
"percent": 2.
|
|
164
|
+
"percent": 2.43,
|
|
165
165
|
"reduction": 22.27
|
|
166
166
|
},
|
|
167
167
|
{
|
|
@@ -259,7 +259,7 @@
|
|
|
259
259
|
"dependents": [
|
|
260
260
|
"/src/adapters/fetch/index.ts"
|
|
261
261
|
],
|
|
262
|
-
"percent": 1.
|
|
262
|
+
"percent": 1.75,
|
|
263
263
|
"reduction": 2.17
|
|
264
264
|
},
|
|
265
265
|
{
|
|
@@ -278,34 +278,34 @@
|
|
|
278
278
|
"reduction": 13.79
|
|
279
279
|
},
|
|
280
280
|
{
|
|
281
|
-
"id": "/src/
|
|
282
|
-
"size":
|
|
283
|
-
"origSize":
|
|
281
|
+
"id": "/src/adapters/next-app-dir/rethrowNextErrors.ts",
|
|
282
|
+
"size": 2050,
|
|
283
|
+
"origSize": 2176,
|
|
284
284
|
"renderedExports": [
|
|
285
|
-
"
|
|
286
|
-
"createFlatProxy"
|
|
285
|
+
"rethrowNextErrors"
|
|
287
286
|
],
|
|
288
287
|
"removedExports": [],
|
|
289
288
|
"dependents": [
|
|
290
|
-
"/src/
|
|
291
|
-
"/src/unstable-core-do-not-import/router.ts"
|
|
289
|
+
"/src/adapters/next-app-dir/nextAppDirCaller.ts"
|
|
292
290
|
],
|
|
293
|
-
"percent": 1.
|
|
294
|
-
"reduction":
|
|
291
|
+
"percent": 1.59,
|
|
292
|
+
"reduction": 5.79
|
|
295
293
|
},
|
|
296
294
|
{
|
|
297
|
-
"id": "/src/
|
|
298
|
-
"size":
|
|
299
|
-
"origSize":
|
|
295
|
+
"id": "/src/unstable-core-do-not-import/createProxy.ts",
|
|
296
|
+
"size": 1982,
|
|
297
|
+
"origSize": 1991,
|
|
300
298
|
"renderedExports": [
|
|
301
|
-
"
|
|
299
|
+
"createRecursiveProxy",
|
|
300
|
+
"createFlatProxy"
|
|
302
301
|
],
|
|
303
302
|
"removedExports": [],
|
|
304
303
|
"dependents": [
|
|
305
|
-
"/src/
|
|
304
|
+
"/src/unstable-core-do-not-import.ts",
|
|
305
|
+
"/src/unstable-core-do-not-import/router.ts"
|
|
306
306
|
],
|
|
307
|
-
"percent": 1.
|
|
308
|
-
"reduction":
|
|
307
|
+
"percent": 1.53,
|
|
308
|
+
"reduction": 0.45
|
|
309
309
|
},
|
|
310
310
|
{
|
|
311
311
|
"id": "/src/unstable-core-do-not-import/error/TRPCError.ts",
|
|
@@ -384,8 +384,8 @@
|
|
|
384
384
|
},
|
|
385
385
|
{
|
|
386
386
|
"id": "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
|
|
387
|
-
"size":
|
|
388
|
-
"origSize":
|
|
387
|
+
"size": 1287,
|
|
388
|
+
"origSize": 1583,
|
|
389
389
|
"renderedExports": [
|
|
390
390
|
"getHTTPStatusCode",
|
|
391
391
|
"getHTTPStatusCodeFromError"
|
|
@@ -396,8 +396,8 @@
|
|
|
396
396
|
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
397
397
|
"/src/unstable-core-do-not-import/error/getErrorShape.ts"
|
|
398
398
|
],
|
|
399
|
-
"percent":
|
|
400
|
-
"reduction":
|
|
399
|
+
"percent": 1,
|
|
400
|
+
"reduction": 18.7
|
|
401
401
|
},
|
|
402
402
|
{
|
|
403
403
|
"id": "/src/unstable-core-do-not-import/utils.ts",
|
|
@@ -415,14 +415,15 @@
|
|
|
415
415
|
"removedExports": [],
|
|
416
416
|
"dependents": [
|
|
417
417
|
"/src/unstable-core-do-not-import.ts",
|
|
418
|
+
"/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
|
|
418
419
|
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
419
420
|
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
421
|
+
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
420
422
|
"/src/unstable-core-do-not-import/error/TRPCError.ts",
|
|
421
423
|
"/src/unstable-core-do-not-import/stream/sse.ts",
|
|
422
424
|
"/src/unstable-core-do-not-import/transformer.ts",
|
|
423
425
|
"/src/unstable-core-do-not-import/middleware.ts",
|
|
424
426
|
"/src/unstable-core-do-not-import/router.ts",
|
|
425
|
-
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
426
427
|
"/src/unstable-core-do-not-import/http/contentType.ts",
|
|
427
428
|
"/src/unstable-core-do-not-import/procedureBuilder.ts",
|
|
428
429
|
"/src/unstable-core-do-not-import/stream/jsonl.ts"
|
|
@@ -577,7 +578,7 @@
|
|
|
577
578
|
"/src/unstable-core-do-not-import/stream/sse.ts",
|
|
578
579
|
"/src/unstable-core-do-not-import/stream/jsonl.ts"
|
|
579
580
|
],
|
|
580
|
-
"percent": 0.
|
|
581
|
+
"percent": 0.45,
|
|
581
582
|
"reduction": 17.15
|
|
582
583
|
},
|
|
583
584
|
{
|
|
@@ -720,9 +721,9 @@
|
|
|
720
721
|
"reduction": 100
|
|
721
722
|
},
|
|
722
723
|
{
|
|
723
|
-
"id": "/src/
|
|
724
|
+
"id": "/src/rpc.ts",
|
|
724
725
|
"size": 0,
|
|
725
|
-
"origSize":
|
|
726
|
+
"origSize": 36,
|
|
726
727
|
"renderedExports": [],
|
|
727
728
|
"removedExports": [],
|
|
728
729
|
"dependents": [],
|
|
@@ -730,9 +731,9 @@
|
|
|
730
731
|
"reduction": 100
|
|
731
732
|
},
|
|
732
733
|
{
|
|
733
|
-
"id": "/src/
|
|
734
|
+
"id": "/src/index.ts",
|
|
734
735
|
"size": 0,
|
|
735
|
-
"origSize":
|
|
736
|
+
"origSize": 32,
|
|
736
737
|
"renderedExports": [],
|
|
737
738
|
"removedExports": [],
|
|
738
739
|
"dependents": [],
|
|
@@ -783,6 +784,16 @@
|
|
|
783
784
|
"percent": 0,
|
|
784
785
|
"reduction": 100
|
|
785
786
|
},
|
|
787
|
+
{
|
|
788
|
+
"id": "/src/adapters/fetch/index.ts",
|
|
789
|
+
"size": 0,
|
|
790
|
+
"origSize": 64,
|
|
791
|
+
"renderedExports": [],
|
|
792
|
+
"removedExports": [],
|
|
793
|
+
"dependents": [],
|
|
794
|
+
"percent": 0,
|
|
795
|
+
"reduction": 100
|
|
796
|
+
},
|
|
786
797
|
{
|
|
787
798
|
"id": "/src/adapters/fastify/index.ts",
|
|
788
799
|
"size": 0,
|
|
@@ -801,22 +812,12 @@
|
|
|
801
812
|
"removedExports": [],
|
|
802
813
|
"dependents": [
|
|
803
814
|
"/src/adapters/express.ts",
|
|
804
|
-
"/src/adapters/standalone.ts",
|
|
805
815
|
"/src/adapters/next.ts",
|
|
816
|
+
"/src/adapters/standalone.ts",
|
|
806
817
|
"/src/adapters/fastify/fastifyRequestHandler.ts"
|
|
807
818
|
],
|
|
808
819
|
"percent": 0,
|
|
809
820
|
"reduction": 100
|
|
810
|
-
},
|
|
811
|
-
{
|
|
812
|
-
"id": "/src/adapters/fetch/index.ts",
|
|
813
|
-
"size": 0,
|
|
814
|
-
"origSize": 64,
|
|
815
|
-
"renderedExports": [],
|
|
816
|
-
"removedExports": [],
|
|
817
|
-
"dependents": [],
|
|
818
|
-
"percent": 0,
|
|
819
|
-
"reduction": 100
|
|
820
821
|
}
|
|
821
822
|
],
|
|
822
823
|
"moduleCount": 55
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createProxy.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/createProxy.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AACD,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"createProxy.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/createProxy.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AACD,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC;AAyC7D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,sBAC9B,aAAa,KACtB,KAAqE,CAAC;AAEzE;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,YACzB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,KAAK,KAAK,GAAG,KAC5C,KAWF,CAAC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _cache, _cacheKey;
|
|
4
3
|
const noop = ()=>{
|
|
5
4
|
// noop
|
|
6
5
|
};
|
|
7
6
|
function createInnerProxy(callback, path, cache) {
|
|
8
|
-
|
|
9
|
-
(_cache = cache)[_cacheKey = cacheKey] ?? (_cache[_cacheKey] = new Proxy(noop, {
|
|
7
|
+
return new Proxy(noop, {
|
|
10
8
|
get (_obj, key) {
|
|
11
9
|
if (typeof key !== 'string' || key === 'then') {
|
|
12
10
|
// special case for if the proxy is accidentally treated
|
|
@@ -16,7 +14,7 @@ function createInnerProxy(callback, path, cache) {
|
|
|
16
14
|
return createInnerProxy(callback, [
|
|
17
15
|
...path,
|
|
18
16
|
key
|
|
19
|
-
]
|
|
17
|
+
]);
|
|
20
18
|
},
|
|
21
19
|
apply (_1, _2, args) {
|
|
22
20
|
const lastOfPath = path[path.length - 1];
|
|
@@ -40,14 +38,13 @@ function createInnerProxy(callback, path, cache) {
|
|
|
40
38
|
}
|
|
41
39
|
return callback(opts);
|
|
42
40
|
}
|
|
43
|
-
})
|
|
44
|
-
return cache[cacheKey];
|
|
41
|
+
});
|
|
45
42
|
}
|
|
46
43
|
/**
|
|
47
44
|
* Creates a proxy that calls the callback with the path and arguments
|
|
48
45
|
*
|
|
49
46
|
* @internal
|
|
50
|
-
*/ const createRecursiveProxy = (callback)=>createInnerProxy(callback, []
|
|
47
|
+
*/ const createRecursiveProxy = (callback)=>createInnerProxy(callback, []);
|
|
51
48
|
/**
|
|
52
49
|
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
53
50
|
*
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
var _cache, _cacheKey;
|
|
2
1
|
const noop = ()=>{
|
|
3
2
|
// noop
|
|
4
3
|
};
|
|
5
4
|
function createInnerProxy(callback, path, cache) {
|
|
6
|
-
|
|
7
|
-
(_cache = cache)[_cacheKey = cacheKey] ?? (_cache[_cacheKey] = new Proxy(noop, {
|
|
5
|
+
return new Proxy(noop, {
|
|
8
6
|
get (_obj, key) {
|
|
9
7
|
if (typeof key !== 'string' || key === 'then') {
|
|
10
8
|
// special case for if the proxy is accidentally treated
|
|
@@ -14,7 +12,7 @@ function createInnerProxy(callback, path, cache) {
|
|
|
14
12
|
return createInnerProxy(callback, [
|
|
15
13
|
...path,
|
|
16
14
|
key
|
|
17
|
-
]
|
|
15
|
+
]);
|
|
18
16
|
},
|
|
19
17
|
apply (_1, _2, args) {
|
|
20
18
|
const lastOfPath = path[path.length - 1];
|
|
@@ -38,14 +36,13 @@ function createInnerProxy(callback, path, cache) {
|
|
|
38
36
|
}
|
|
39
37
|
return callback(opts);
|
|
40
38
|
}
|
|
41
|
-
})
|
|
42
|
-
return cache[cacheKey];
|
|
39
|
+
});
|
|
43
40
|
}
|
|
44
41
|
/**
|
|
45
42
|
* Creates a proxy that calls the callback with the path and arguments
|
|
46
43
|
*
|
|
47
44
|
* @internal
|
|
48
|
-
*/ const createRecursiveProxy = (callback)=>createInnerProxy(callback, []
|
|
45
|
+
*/ const createRecursiveProxy = (callback)=>createInnerProxy(callback, []);
|
|
49
46
|
/**
|
|
50
47
|
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
51
48
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getHTTPStatusCode.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/getHTTPStatusCode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getHTTPStatusCode.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/getHTTPStatusCode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,QAAQ,CAAC;AA8BpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,MAAM,CAsB7E;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,UAE1D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var codes = require('../rpc/codes.js');
|
|
4
|
+
var utils = require('../utils.js');
|
|
4
5
|
|
|
5
6
|
const JSONRPC2_TO_HTTP_CODE = {
|
|
6
7
|
PARSE_ERROR: 400,
|
|
@@ -28,10 +29,9 @@ function getHTTPStatusCode(json) {
|
|
|
28
29
|
json
|
|
29
30
|
];
|
|
30
31
|
const httpStatuses = new Set(arr.map((res)=>{
|
|
31
|
-
if ('error' in res) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return data.httpStatus;
|
|
32
|
+
if ('error' in res && utils.isObject(res.error.data)) {
|
|
33
|
+
if (typeof res.error.data?.['httpStatus'] === 'number') {
|
|
34
|
+
return res.error.data['httpStatus'];
|
|
35
35
|
}
|
|
36
36
|
const code = codes.TRPC_ERROR_CODES_BY_NUMBER[res.error.code];
|
|
37
37
|
return getStatusCodeFromKey(code);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TRPC_ERROR_CODES_BY_NUMBER } from '../rpc/codes.mjs';
|
|
2
|
+
import { isObject } from '../utils.mjs';
|
|
2
3
|
|
|
3
4
|
const JSONRPC2_TO_HTTP_CODE = {
|
|
4
5
|
PARSE_ERROR: 400,
|
|
@@ -26,10 +27,9 @@ function getHTTPStatusCode(json) {
|
|
|
26
27
|
json
|
|
27
28
|
];
|
|
28
29
|
const httpStatuses = new Set(arr.map((res)=>{
|
|
29
|
-
if ('error' in res) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return data.httpStatus;
|
|
30
|
+
if ('error' in res && isObject(res.error.data)) {
|
|
31
|
+
if (typeof res.error.data?.['httpStatus'] === 'number') {
|
|
32
|
+
return res.error.data['httpStatus'];
|
|
33
33
|
}
|
|
34
34
|
const code = TRPC_ERROR_CODES_BY_NUMBER[res.error.code];
|
|
35
35
|
return getStatusCodeFromKey(code);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "11.0.0-rc.
|
|
3
|
+
"version": "11.0.0-rc.439+775af00cc",
|
|
4
4
|
"description": "The tRPC server library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
"react-dom": "^18.3.1",
|
|
138
138
|
"rollup": "^4.9.5",
|
|
139
139
|
"superjson": "^1.12.4",
|
|
140
|
-
"superstruct": "^
|
|
140
|
+
"superstruct": "^2.0.0",
|
|
141
141
|
"tslib": "^2.5.0",
|
|
142
142
|
"tsx": "^4.0.0",
|
|
143
143
|
"typescript": "^5.5.0",
|
|
@@ -149,5 +149,5 @@
|
|
|
149
149
|
"funding": [
|
|
150
150
|
"https://trpc.io/sponsor"
|
|
151
151
|
],
|
|
152
|
-
"gitHead": "
|
|
152
|
+
"gitHead": "775af00cc25f1a2397e3f5d7f811f6a8a4b0aa82"
|
|
153
153
|
}
|
|
@@ -13,9 +13,7 @@ function createInnerProxy(
|
|
|
13
13
|
path: string[],
|
|
14
14
|
cache: Record<string, unknown>,
|
|
15
15
|
) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
cache[cacheKey] ??= new Proxy(noop, {
|
|
16
|
+
return new Proxy(noop, {
|
|
19
17
|
get(_obj, key) {
|
|
20
18
|
if (typeof key !== 'string' || key === 'then') {
|
|
21
19
|
// special case for if the proxy is accidentally treated
|
|
@@ -43,8 +41,6 @@ function createInnerProxy(
|
|
|
43
41
|
return callback(opts);
|
|
44
42
|
},
|
|
45
43
|
});
|
|
46
|
-
|
|
47
|
-
return cache[cacheKey];
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { DefaultErrorData } from '../error/formatter';
|
|
2
1
|
import type { TRPCError } from '../error/TRPCError';
|
|
3
2
|
import type { TRPC_ERROR_CODES_BY_KEY, TRPCResponse } from '../rpc';
|
|
4
3
|
import { TRPC_ERROR_CODES_BY_NUMBER } from '../rpc';
|
|
4
|
+
import { isObject } from '../utils';
|
|
5
5
|
|
|
6
6
|
const JSONRPC2_TO_HTTP_CODE: Record<
|
|
7
7
|
keyof typeof TRPC_ERROR_CODES_BY_KEY,
|
|
@@ -33,12 +33,9 @@ export function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]): number {
|
|
|
33
33
|
const arr = Array.isArray(json) ? json : [json];
|
|
34
34
|
const httpStatuses = new Set<number>(
|
|
35
35
|
arr.map((res) => {
|
|
36
|
-
if ('error' in res) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
| DefaultErrorData;
|
|
40
|
-
if (typeof data.httpStatus === 'number') {
|
|
41
|
-
return data.httpStatus;
|
|
36
|
+
if ('error' in res && isObject(res.error.data)) {
|
|
37
|
+
if (typeof res.error.data?.['httpStatus'] === 'number') {
|
|
38
|
+
return res.error.data['httpStatus'];
|
|
42
39
|
}
|
|
43
40
|
const code = TRPC_ERROR_CODES_BY_NUMBER[res.error.code];
|
|
44
41
|
return getStatusCodeFromKey(code);
|