Skip to content

Commit 0d082d9

Browse files
committed
feat: bump typed-express-router to 2.0.0
Ticket: DX-1672
1 parent 998a213 commit 0d082d9

File tree

8 files changed

+41
-8
lines changed

8 files changed

+41
-8
lines changed

package-lock.json

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@api-ts/openapi-generator": "^5.7.0",
2828
"@api-ts/response": "^2.1.0",
2929
"@api-ts/superagent-wrapper": "^1.3.3",
30-
"@api-ts/typed-express-router": "^1.1.13",
30+
"@api-ts/typed-express-router": "2.0.0",
3131
"@bitgo-beta/abstract-cosmos": "^1.0.1-beta.1049",
3232
"@bitgo-beta/abstract-eth": "1.0.2-beta.1298",
3333
"@bitgo-beta/abstract-utxo": "1.1.1-beta.1301",

src/advancedWalletManager/routers/advancedWalletManagerApiSpec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { ecdsaMPCv2Finalize } from '../handlers/ecdsaMPCV2WalletGenerationFinali
3535
import { ecdsaMPCv2Recovery } from '../handlers/ecdsaMPCV2Recovery';
3636
import { signEddsaRecoveryTransaction } from '../handlers/eddsaMPCRecovery';
3737
import { isEddsaCoin } from '../../shared/coinUtils';
38+
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';
3839

3940
// Request type for /key/independent endpoint
4041
const IndependentKeyRequest = {
@@ -489,7 +490,9 @@ export type GenericAwmApiSpecRouteRequest = AwmApiSpecRouteRequest<any, any>;
489490
export function createKeyGenRouter(
490491
config: AdvancedWalletManagerConfig,
491492
): WrappedRouter<typeof AdvancedWalletManagerApiSpec> {
492-
const router = createRouter(AdvancedWalletManagerApiSpec);
493+
const router = createRouter(AdvancedWalletManagerApiSpec, {
494+
decodeErrorFormatter: customDecodeErrorFormatter,
495+
});
493496
// Add middleware
494497
router.use(express.json());
495498
router.use(prepareBitGo(config));

src/advancedWalletManager/routers/healthCheck.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Response } from '@api-ts/response';
44
import pjson from '../../../package.json';
55
import { responseHandler } from '../../shared/middleware';
66
import { PingResponseType, VersionResponseType } from '../../types/health';
7+
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';
78

89
// API Response types
910
const PingResponse: HttpResponse = {
@@ -38,7 +39,9 @@ export const HealthCheckApiSpec = apiSpec({
3839

3940
// Create router with handlers
4041
export function createHealthCheckRouter(): WrappedRouter<typeof HealthCheckApiSpec> {
41-
const router = createRouter(HealthCheckApiSpec);
42+
const router = createRouter(HealthCheckApiSpec, {
43+
decodeErrorFormatter: customDecodeErrorFormatter,
44+
});
4245
// Ping endpoint handler
4346
router.post('v1.health.ping', [
4447
responseHandler(() =>

src/masterBitgoExpress/routers/awmExpressHealth.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import logger from '../../shared/logger';
77
import { responseHandler } from '../../shared/middleware';
88
import { AdvancedWalletManagerClient } from '../clients/advancedWalletManagerClient';
99
import { PingResponseType, VersionResponseType } from '../../types/health';
10+
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';
1011

1112
// Response type for /ping/advancedWalletManager endpoint
1213
const PingAwmResponse: HttpResponse = {
@@ -54,7 +55,9 @@ export const AdvancedWalletManagerHealthSpec = apiSpec({
5455
export function createAdvancedWalletManagerHealthRouter(
5556
cfg: MasterExpressConfig,
5657
): WrappedRouter<typeof AdvancedWalletManagerHealthSpec> {
57-
const router = createRouter(AdvancedWalletManagerHealthSpec);
58+
const router = createRouter(AdvancedWalletManagerHealthSpec, {
59+
decodeErrorFormatter: customDecodeErrorFormatter,
60+
});
5861

5962
// Create an instance of awmClient
6063
const awmClient = new AdvancedWalletManagerClient(cfg);

src/masterBitgoExpress/routers/healthCheck.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Response } from '@api-ts/response';
44
import pjson from '../../../package.json';
55
import { responseHandler } from '../../shared/middleware';
66
import { PingResponseType, VersionResponseType } from '../../types/health';
7+
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';
78

89
// API Response types
910
const PingResponse: HttpResponse = {
@@ -40,7 +41,9 @@ export const HealthCheckApiSpec = apiSpec({
4041
export function createHealthCheckRouter(
4142
serverType: string,
4243
): WrappedRouter<typeof HealthCheckApiSpec> {
43-
const router = createRouter(HealthCheckApiSpec);
44+
const router = createRouter(HealthCheckApiSpec, {
45+
decodeErrorFormatter: customDecodeErrorFormatter,
46+
});
4447

4548
// Ping endpoint handler
4649
router.post('v1.health.ping', [

src/masterBitgoExpress/routers/masterBitGoExpressApiSpec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type WrappedRouter,
77
} from '@api-ts/typed-express-router';
88
import express from 'express';
9+
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';
910
import { MasterExpressConfig } from '../../shared/types';
1011
import * as utxolib from '@bitgo-beta/utxo-lib';
1112
import { prepareBitGo, responseHandler } from '../../shared/middleware';
@@ -82,7 +83,9 @@ export type GenericMasterApiSpecRouteRequest = MasterApiSpecRouteRequest<any, an
8283
export function createMasterApiRouter(
8384
cfg: MasterExpressConfig,
8485
): WrappedRouter<typeof MasterBitGoExpressApiSpec> {
85-
const router = createRouter(MasterBitGoExpressApiSpec);
86+
const router = createRouter(MasterBitGoExpressApiSpec, {
87+
decodeErrorFormatter: customDecodeErrorFormatter,
88+
});
8689

8790
// Add middleware to all routes
8891
router.use(parseBody);

src/shared/errorFormatters.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as PathReporter from 'io-ts/lib/PathReporter';
2+
import { DecodeErrorFormatterFn } from '@api-ts/typed-express-router';
3+
4+
export const customDecodeErrorFormatter: DecodeErrorFormatterFn = (errs, _req) => {
5+
const validationErrors = PathReporter.failure(errs);
6+
const validationErrorMessage = validationErrors.join('\n');
7+
return { error: validationErrorMessage };
8+
};

0 commit comments

Comments
 (0)