@gravity-ui/gateway 1.0.2 → 1.0.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/build/components/grpc.d.ts +1 -1
- package/build/components/grpc.js +12 -12
- package/build/components/mixed.d.ts +1 -1
- package/build/components/mixed.js +3 -3
- package/build/components/rest.d.ts +1 -1
- package/build/components/rest.js +10 -10
- package/build/index.js +8 -8
- package/build/models/common.d.ts +1 -1
- package/build/utils/common.d.ts +1 -1
- package/build/utils/common.js +2 -2
- package/build/utils/parse-error.d.ts +1 -1
- package/build/utils/parse-error.js +2 -2
- package/package.json +2 -1
|
@@ -20,5 +20,5 @@ export interface GrpcContext {
|
|
|
20
20
|
}
|
|
21
21
|
export declare function createRoot(includeGrpcPaths?: string[]): protobufjs.Root;
|
|
22
22
|
export declare function getCredentialsMap(caCertificatePath?: string | null): CredentialsMap;
|
|
23
|
-
export default function createGrpcAction<Context extends GatewayContext>({ root, credentials }: GrpcContext, endpoints: EndpointsConfig | undefined, config: ApiServiceGrpcActionConfig<Context, any, any>, serviceKey: string, actionName: string, options: GatewayApiOptions<Context>,
|
|
23
|
+
export default function createGrpcAction<Context extends GatewayContext>({ root, credentials }: GrpcContext, endpoints: EndpointsConfig | undefined, config: ApiServiceGrpcActionConfig<Context, any, any>, serviceKey: string, actionName: string, options: GatewayApiOptions<Context>, ErrorConstructor: AppErrorConstructor): (actionConfig: ApiActionConfig<Context, any, any>) => Promise<import("../models/common").GatewayActionClientStreamResponse<any> | import("../models/common").GatewayActionServerStreamResponse<any> | import("../models/common").GatewayActionDuplexStreamResponse<any> | import("../models/common").GatewayActionUnaryResponse<any>>;
|
|
24
24
|
export {};
|
package/build/components/grpc.js
CHANGED
|
@@ -97,7 +97,7 @@ function getCredentialsMap(caCertificatePath) {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
exports.getCredentialsMap = getCredentialsMap;
|
|
100
|
-
function decodeResponse(response, packageRoot, ctx, encodedFields = [],
|
|
100
|
+
function decodeResponse(response, packageRoot, ctx, encodedFields = [], ErrorConstructor) {
|
|
101
101
|
const systemFields = ['metadata', 'response', 'error.details'];
|
|
102
102
|
[...systemFields, ...encodedFields].forEach((fieldName) => {
|
|
103
103
|
try {
|
|
@@ -114,7 +114,7 @@ function decodeResponse(response, packageRoot, ctx, encodedFields = [], ErrorCon
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
catch (error) {
|
|
117
|
-
(0, common_2.handleError)(
|
|
117
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'Message decoding failed', { fieldName });
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
120
|
}
|
|
@@ -324,15 +324,15 @@ async function getServiceInstance(root, config, endpointData, grpcOptions, crede
|
|
|
324
324
|
}
|
|
325
325
|
return serviceInstance;
|
|
326
326
|
}
|
|
327
|
-
async function getResponseData({ config, response, ctx, packageRoot, args,
|
|
327
|
+
async function getResponseData({ config, response, ctx, packageRoot, args, ErrorConstructor, }) {
|
|
328
328
|
// Handle operation's runtime protocol buffers
|
|
329
329
|
if (response) {
|
|
330
330
|
const encodedFields = config.encodedFields;
|
|
331
331
|
if (Array.isArray(response)) {
|
|
332
|
-
response.forEach((responseItem) => decodeResponse(responseItem, packageRoot, ctx, encodedFields,
|
|
332
|
+
response.forEach((responseItem) => decodeResponse(responseItem, packageRoot, ctx, encodedFields, ErrorConstructor));
|
|
333
333
|
}
|
|
334
334
|
else if (typeof response === 'object') {
|
|
335
|
-
decodeResponse(response, packageRoot, ctx, encodedFields,
|
|
335
|
+
decodeResponse(response, packageRoot, ctx, encodedFields, ErrorConstructor);
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
let responseData = response;
|
|
@@ -345,12 +345,12 @@ async function getResponseData({ config, response, ctx, packageRoot, args, Error
|
|
|
345
345
|
ctx.log('Transformed response data');
|
|
346
346
|
}
|
|
347
347
|
catch (error) {
|
|
348
|
-
(0, common_2.handleError)(
|
|
348
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'Transform response data failed');
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
return responseData;
|
|
352
352
|
}
|
|
353
|
-
function createGrpcAction({ root, credentials }, endpoints, config, serviceKey, actionName, options,
|
|
353
|
+
function createGrpcAction({ root, credentials }, endpoints, config, serviceKey, actionName, options, ErrorConstructor) {
|
|
354
354
|
const serviceName = (options === null || options === void 0 ? void 0 : options.serviceName) || serviceKey;
|
|
355
355
|
let getService;
|
|
356
356
|
let recreateService;
|
|
@@ -450,7 +450,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
450
450
|
var _a;
|
|
451
451
|
const restStatus = lodash_1.default.get(grpcError.getGatewayError(), 'status', 500);
|
|
452
452
|
sendStats(restStatus, Object.assign(Object.assign({}, requestData), { responseSize: (_a = grpcError.getRawError()) === null || _a === void 0 ? void 0 : _a.metadata, grpcStatus: grpcError.getGatewayError().code }));
|
|
453
|
-
ctx.logError('Request failed',
|
|
453
|
+
ctx.logError('Request failed', ErrorConstructor.wrap(grpcError.getAppError(ErrorConstructor)), Object.assign({ serviceName,
|
|
454
454
|
actionName, debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders) }, grpcError.getGatewayError()));
|
|
455
455
|
ctx.end();
|
|
456
456
|
}
|
|
@@ -460,7 +460,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
460
460
|
params = await config.params(args, headers, { ctx });
|
|
461
461
|
}
|
|
462
462
|
catch (error) {
|
|
463
|
-
(0, common_2.handleError)(
|
|
463
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'Getting config params failed');
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
466
|
let service;
|
|
@@ -468,7 +468,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
468
468
|
service = await getService(args);
|
|
469
469
|
}
|
|
470
470
|
catch (error) {
|
|
471
|
-
(0, common_2.handleError)(
|
|
471
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'getService failed');
|
|
472
472
|
throw error;
|
|
473
473
|
}
|
|
474
474
|
// eslint-disable-next-line complexity
|
|
@@ -619,7 +619,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
619
619
|
service = await getService(args);
|
|
620
620
|
}
|
|
621
621
|
catch (error) {
|
|
622
|
-
(0, common_2.handleError)(
|
|
622
|
+
(0, common_2.handleError)(ErrorConstructor, error, ctx, 'getService failed');
|
|
623
623
|
throw error;
|
|
624
624
|
}
|
|
625
625
|
// Update service
|
|
@@ -637,7 +637,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
637
637
|
config,
|
|
638
638
|
args,
|
|
639
639
|
packageRoot: root,
|
|
640
|
-
|
|
640
|
+
ErrorConstructor,
|
|
641
641
|
});
|
|
642
642
|
Object.assign(debugHeaders, (0, common_2.getHeadersFromMetadata)(trailingMetadata));
|
|
643
643
|
sendStats(200, Object.assign(Object.assign({}, requestData), { responseSize: (0, object_sizeof_1.default)(response), grpcStatus: 0 }));
|
|
@@ -5,7 +5,7 @@ import type { GrpcContext } from './grpc';
|
|
|
5
5
|
export declare function createMixedAction<TSchema extends SchemasByScope, Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse>(config: ApiServiceMixedActionConfig<Context, Req, Res, any, any, any>, api: ApiByScope<TSchema, Context, Req, Res>, serviceName: string, actionName: string, extra: {
|
|
6
6
|
config: GatewayConfig<Context, Req, Res>;
|
|
7
7
|
grpcContext: GrpcContext;
|
|
8
|
-
},
|
|
8
|
+
}, ErrorConstructor: AppErrorConstructor): (actionConfig: ApiActionConfig<Context, any>) => Promise<{
|
|
9
9
|
responseData: any;
|
|
10
10
|
debugHeaders: {};
|
|
11
11
|
}>;
|
|
@@ -16,7 +16,7 @@ const constants_1 = require("../constants");
|
|
|
16
16
|
const common_1 = require("../utils/common");
|
|
17
17
|
const create_context_api_1 = require("../utils/create-context-api");
|
|
18
18
|
const parse_error_1 = require("../utils/parse-error");
|
|
19
|
-
function createMixedAction(config, api, serviceName, actionName, extra,
|
|
19
|
+
function createMixedAction(config, api, serviceName, actionName, extra, ErrorConstructor) {
|
|
20
20
|
return async (actionConfig) => {
|
|
21
21
|
const { args } = actionConfig, context = __rest(actionConfig, ["args"]);
|
|
22
22
|
const ctx = actionConfig.ctx.create(`Gateway ${serviceName} ${actionName} [mixed]`, {
|
|
@@ -37,7 +37,7 @@ function createMixedAction(config, api, serviceName, actionName, extra, ErrorCon
|
|
|
37
37
|
}
|
|
38
38
|
catch (e) {
|
|
39
39
|
if (e instanceof Object && 'error' in e) {
|
|
40
|
-
(0, common_1.handleError)(
|
|
40
|
+
(0, common_1.handleError)(ErrorConstructor, e, ctx, 'Request failed', {
|
|
41
41
|
actionName,
|
|
42
42
|
serviceName,
|
|
43
43
|
});
|
|
@@ -45,7 +45,7 @@ function createMixedAction(config, api, serviceName, actionName, extra, ErrorCon
|
|
|
45
45
|
}
|
|
46
46
|
if (e instanceof Error) {
|
|
47
47
|
const parsedError = (0, parse_error_1.parseMixedError)(e);
|
|
48
|
-
ctx.logError('Request failed',
|
|
48
|
+
ctx.logError('Request failed', ErrorConstructor.wrap(e), {
|
|
49
49
|
actionName,
|
|
50
50
|
serviceName,
|
|
51
51
|
parsedError,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApiActionConfig, ApiServiceRestActionConfig, EndpointsConfig, GatewayApiOptions, Headers } from '../models/common';
|
|
2
2
|
import { GatewayContext } from '../models/context';
|
|
3
3
|
import { AppErrorConstructor } from '../models/error';
|
|
4
|
-
export default function createRestAction<Context extends GatewayContext>(endpoints: EndpointsConfig | undefined, config: ApiServiceRestActionConfig<Context, any, any>, serviceKey: string, actionName: string, options: GatewayApiOptions<Context>,
|
|
4
|
+
export default function createRestAction<Context extends GatewayContext>(endpoints: EndpointsConfig | undefined, config: ApiServiceRestActionConfig<Context, any, any>, serviceKey: string, actionName: string, options: GatewayApiOptions<Context>, ErrorConstructor: AppErrorConstructor): (actionConfig: ApiActionConfig<Context, any>) => Promise<{
|
|
5
5
|
responseData: unknown;
|
|
6
6
|
debugHeaders: Headers;
|
|
7
7
|
}>;
|
package/build/components/rest.js
CHANGED
|
@@ -13,14 +13,14 @@ const common_1 = require("../utils/common");
|
|
|
13
13
|
const parse_error_1 = require("../utils/parse-error");
|
|
14
14
|
const redact_sensitive_headers_1 = require("../utils/redact-sensitive-headers");
|
|
15
15
|
const validate_1 = require("../utils/validate");
|
|
16
|
-
function getRestResponseSize(data, ctx,
|
|
16
|
+
function getRestResponseSize(data, ctx, ErrorConstructor) {
|
|
17
17
|
var _a;
|
|
18
18
|
let responseSize = 0;
|
|
19
19
|
try {
|
|
20
20
|
responseSize = constants_1.ECMA_STRING_SIZE * ((_a = JSON.stringify(data)) === null || _a === void 0 ? void 0 : _a.length);
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|
|
23
|
-
(0, common_1.handleError)(
|
|
23
|
+
(0, common_1.handleError)(ErrorConstructor, error, ctx, 'Calculate response size failed');
|
|
24
24
|
}
|
|
25
25
|
return responseSize;
|
|
26
26
|
}
|
|
@@ -33,7 +33,7 @@ function getConfigSerializerFunction(config) {
|
|
|
33
33
|
}
|
|
34
34
|
return undefined;
|
|
35
35
|
}
|
|
36
|
-
function createRestAction(endpoints, config, serviceKey, actionName, options,
|
|
36
|
+
function createRestAction(endpoints, config, serviceKey, actionName, options, ErrorConstructor) {
|
|
37
37
|
var _a;
|
|
38
38
|
const timeout = (_a = config === null || config === void 0 ? void 0 : config.timeout) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.timeout;
|
|
39
39
|
const defaultAxiosClient = (0, axios_1.getAxiosClient)(timeout, config === null || config === void 0 ? void 0 : config.retries, options === null || options === void 0 ? void 0 : options.axiosConfig);
|
|
@@ -150,7 +150,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
150
150
|
params = await config.params(args, actionHeaders, { ctx });
|
|
151
151
|
}
|
|
152
152
|
catch (error) {
|
|
153
|
-
(0, common_1.handleError)(
|
|
153
|
+
(0, common_1.handleError)(ErrorConstructor, error, ctx, 'Getting config params failed');
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
const { body = undefined, query = undefined, headers = actionHeaders } = params !== null && params !== void 0 ? params : {};
|
|
@@ -171,7 +171,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
catch (error) {
|
|
174
|
-
(0, common_1.handleError)(
|
|
174
|
+
(0, common_1.handleError)(ErrorConstructor, error, ctx, 'Stringify request body failed');
|
|
175
175
|
}
|
|
176
176
|
Object.assign(debugHeaders, {
|
|
177
177
|
'x-api-request-method': config.method,
|
|
@@ -227,11 +227,11 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
227
227
|
ctx.log('Transformed response data');
|
|
228
228
|
}
|
|
229
229
|
catch (error) {
|
|
230
|
-
(0, common_1.handleError)(
|
|
230
|
+
(0, common_1.handleError)(ErrorConstructor, error, ctx, 'Transform response data failed');
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
if (options === null || options === void 0 ? void 0 : options.sendStats) {
|
|
234
|
-
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize(response === null || response === void 0 ? void 0 : response.data, ctx,
|
|
234
|
+
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize(response === null || response === void 0 ? void 0 : response.data, ctx, ErrorConstructor), restStatus: 200 }), (0, redact_sensitive_headers_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
235
235
|
}
|
|
236
236
|
else {
|
|
237
237
|
ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus: 200 }));
|
|
@@ -256,7 +256,7 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
256
256
|
ctx.log('Transformed response error');
|
|
257
257
|
}
|
|
258
258
|
catch (error) {
|
|
259
|
-
(0, common_1.handleError)(
|
|
259
|
+
(0, common_1.handleError)(ErrorConstructor, error, ctx, 'Transform response error failed');
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
if (!parsedError) {
|
|
@@ -264,12 +264,12 @@ function createRestAction(endpoints, config, serviceKey, actionName, options, Er
|
|
|
264
264
|
parsedError = (0, parse_error_1.parseRestError)(error, lang);
|
|
265
265
|
}
|
|
266
266
|
catch (error) {
|
|
267
|
-
(0, common_1.handleError)(
|
|
267
|
+
(0, common_1.handleError)(ErrorConstructor, error, ctx, 'Error parse rest error');
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
const responseStatus = lodash_1.default.get(parsedError, 'status') || lodash_1.default.get(error, 'status', 500);
|
|
271
271
|
if (options === null || options === void 0 ? void 0 : options.sendStats) {
|
|
272
|
-
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize((_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data, ctx,
|
|
272
|
+
options.sendStats(Object.assign(Object.assign({}, requestData), { responseSize: getRestResponseSize((_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data, ctx, ErrorConstructor), restStatus: responseStatus }), (0, redact_sensitive_headers_1.redactSensitiveHeaders)(parentCtx, headers), parentCtx, { debugHeaders: (0, common_1.sanitizeDebugHeaders)(debugHeaders) });
|
|
273
273
|
}
|
|
274
274
|
else {
|
|
275
275
|
ctx.stats(Object.assign(Object.assign({}, requestData), { responseStatus }));
|
package/build/index.js
CHANGED
|
@@ -50,13 +50,13 @@ function isRestActionConfig(actionConfig) {
|
|
|
50
50
|
function createApiAction(schema, config, serviceKey, actionName, api, grpcContext) {
|
|
51
51
|
const serviceSchema = schema[serviceKey];
|
|
52
52
|
if (!serviceSchema) {
|
|
53
|
-
throw new config.
|
|
53
|
+
throw new config.ErrorConstructor(`Gateway config error. Service "${serviceKey}" have been not found.`, {
|
|
54
54
|
code: 'SERVICE_NOT_FOUND',
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
const action = serviceSchema.actions[actionName];
|
|
58
58
|
if (!action) {
|
|
59
|
-
throw new config.
|
|
59
|
+
throw new config.ErrorConstructor(`Gateway config error. Action "${serviceKey}.${actionName}" have been not found.`, {
|
|
60
60
|
code: 'ACTION_NOT_FOUND',
|
|
61
61
|
});
|
|
62
62
|
}
|
|
@@ -65,7 +65,7 @@ function createApiAction(schema, config, serviceKey, actionName, api, grpcContex
|
|
|
65
65
|
const env = config.env || '';
|
|
66
66
|
if (isMixedActionConfig(action)) {
|
|
67
67
|
const resultServiceName = serviceName || serviceKey;
|
|
68
|
-
return (0, mixed_1.createMixedAction)(action, api, resultServiceName, actionName, { config, grpcContext }, config.
|
|
68
|
+
return (0, mixed_1.createMixedAction)(action, api, resultServiceName, actionName, { config, grpcContext }, config.ErrorConstructor);
|
|
69
69
|
}
|
|
70
70
|
const endpointsConfig = lodash_1.default.get(serviceSchema.endpoints, [installation, env]);
|
|
71
71
|
if (isRestActionConfig(action)) {
|
|
@@ -78,7 +78,7 @@ function createApiAction(schema, config, serviceKey, actionName, api, grpcContex
|
|
|
78
78
|
validationSchema: config.validationSchema,
|
|
79
79
|
encodePathArgs: config.encodePathArgs,
|
|
80
80
|
getAuthHeaders: config.getAuthHeaders,
|
|
81
|
-
}, config.
|
|
81
|
+
}, config.ErrorConstructor);
|
|
82
82
|
}
|
|
83
83
|
return (0, grpc_1.default)(grpcContext, endpointsConfig, action, serviceKey, actionName, {
|
|
84
84
|
serviceName,
|
|
@@ -88,17 +88,17 @@ function createApiAction(schema, config, serviceKey, actionName, api, grpcContex
|
|
|
88
88
|
grpcOptions: config.grpcOptions,
|
|
89
89
|
grpcRecreateService: config.grpcRecreateService,
|
|
90
90
|
getAuthHeaders: config.getAuthHeaders,
|
|
91
|
-
}, config.
|
|
91
|
+
}, config.ErrorConstructor);
|
|
92
92
|
}
|
|
93
93
|
function generateGatewayApi(schema, config, grpcContext, baseApi) {
|
|
94
94
|
const { installation, env } = config;
|
|
95
95
|
if (!installation) {
|
|
96
|
-
throw new config.
|
|
96
|
+
throw new config.ErrorConstructor('Gateway config error', {
|
|
97
97
|
code: 'EMPTY_GATEWAY_INSTALLATION',
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
if (!env) {
|
|
101
|
-
throw new config.
|
|
101
|
+
throw new config.ErrorConstructor('Gateway config error', { code: 'EMPTY_GATEWAY_ENV' });
|
|
102
102
|
}
|
|
103
103
|
return Object.keys(schema).reduce((api, serviceKey) => {
|
|
104
104
|
return lodash_1.default.set(api, serviceKey, Object.keys(schema[serviceKey].actions).reduce((serviceActions, actionName) => (Object.assign(Object.assign({}, serviceActions), { [actionName]: createApiAction(schema, config, serviceKey, actionName, baseApi, grpcContext) })), {}));
|
|
@@ -172,7 +172,7 @@ function generateGatewayApiController(schemasByScope, Api, config, controllerAct
|
|
|
172
172
|
await onBeforeAction(req, res, scope, service, action, actionConfig);
|
|
173
173
|
}
|
|
174
174
|
catch (error) {
|
|
175
|
-
(0, common_1.handleError)(config.
|
|
175
|
+
(0, common_1.handleError)(config.ErrorConstructor, error, req.ctx, 'Before action handler error');
|
|
176
176
|
throw { error, debugHeaders: {} };
|
|
177
177
|
}
|
|
178
178
|
}
|
package/build/models/common.d.ts
CHANGED
|
@@ -236,6 +236,6 @@ export interface GatewayConfig<Context extends GatewayContext, Req extends Gatew
|
|
|
236
236
|
encodePathArgs?: boolean;
|
|
237
237
|
getAuthArgs: (req: Req, res: Res) => Record<string, unknown> | undefined;
|
|
238
238
|
getAuthHeaders: GetAuthHeaders;
|
|
239
|
-
|
|
239
|
+
ErrorConstructor: AppErrorConstructor;
|
|
240
240
|
}
|
|
241
241
|
export {};
|
package/build/utils/common.d.ts
CHANGED
|
@@ -12,4 +12,4 @@ export declare function getKeys<T extends object>(obj: T): (keyof T)[];
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function sanitizeDebugHeaders(debugHeaders: Headers): _.Omit<Headers, "x-api-request-body">;
|
|
14
14
|
export declare function getHeadersFromMetadata(metadata: Record<string, grpc.MetadataValue[]>): Record<string, string>;
|
|
15
|
-
export declare function handleError<Context extends GatewayContext>(
|
|
15
|
+
export declare function handleError<Context extends GatewayContext>(ErrorConstructor: AppErrorConstructor, error: unknown, ctx: Context, message: string, extra?: Dict): void;
|
package/build/utils/common.js
CHANGED
|
@@ -39,9 +39,9 @@ function getHeadersFromMetadata(metadata) {
|
|
|
39
39
|
}, {});
|
|
40
40
|
}
|
|
41
41
|
exports.getHeadersFromMetadata = getHeadersFromMetadata;
|
|
42
|
-
function handleError(
|
|
42
|
+
function handleError(ErrorConstructor, error, ctx, message, extra) {
|
|
43
43
|
if (error instanceof Error) {
|
|
44
|
-
ctx.logError(message,
|
|
44
|
+
ctx.logError(message, ErrorConstructor.wrap(error), extra);
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
ctx.logError(message, JSON.stringify(error), extra);
|
|
@@ -26,7 +26,7 @@ export declare class GrpcError extends Error {
|
|
|
26
26
|
constructor(message: string, parsedError: GatewayError, rawError?: grpc.ServiceError);
|
|
27
27
|
getGatewayError(): GatewayError;
|
|
28
28
|
getRawError(): grpc.ServiceError | undefined;
|
|
29
|
-
getAppError(
|
|
29
|
+
getAppError(ErrorConstructor: AppErrorConstructor): Error;
|
|
30
30
|
}
|
|
31
31
|
export declare function isGrpcError(error: Error | GrpcError): error is GrpcError;
|
|
32
32
|
export declare function grpcErrorFactory(error: Error): GrpcError;
|
|
@@ -200,8 +200,8 @@ class GrpcError extends Error {
|
|
|
200
200
|
getRawError() {
|
|
201
201
|
return this.rawError;
|
|
202
202
|
}
|
|
203
|
-
getAppError(
|
|
204
|
-
return new
|
|
203
|
+
getAppError(ErrorConstructor) {
|
|
204
|
+
return new ErrorConstructor(this.parsedError.message, {
|
|
205
205
|
code: this.parsedError.code,
|
|
206
206
|
details: this.parsedError.details,
|
|
207
207
|
debug: this.parsedError.debug,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/gateway",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "build/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"bin",
|
|
11
11
|
"patches"
|
|
12
12
|
],
|
|
13
|
+
"types": "build/index.d.ts",
|
|
13
14
|
"bin": {
|
|
14
15
|
"gateway-reflection-patch": "bin/patch.js"
|
|
15
16
|
},
|