Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@api-ts/openapi-generator": "^5.7.0",
"@api-ts/response": "^2.1.0",
"@api-ts/superagent-wrapper": "^1.3.3",
"@api-ts/typed-express-router": "^1.1.13",
"@api-ts/typed-express-router": "2.0.0",
"@bitgo-beta/abstract-cosmos": "^1.0.1-beta.1049",
"@bitgo-beta/abstract-eth": "1.0.2-beta.1298",
"@bitgo-beta/abstract-utxo": "1.1.1-beta.1301",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ecdsaMPCv2Finalize } from '../handlers/ecdsaMPCV2WalletGenerationFinali
import { ecdsaMPCv2Recovery } from '../handlers/ecdsaMPCV2Recovery';
import { signEddsaRecoveryTransaction } from '../handlers/eddsaMPCRecovery';
import { isEddsaCoin } from '../../shared/coinUtils';
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';

// Request type for /key/independent endpoint
const IndependentKeyRequest = {
Expand Down Expand Up @@ -489,7 +490,9 @@ export type GenericAwmApiSpecRouteRequest = AwmApiSpecRouteRequest<any, any>;
export function createKeyGenRouter(
config: AdvancedWalletManagerConfig,
): WrappedRouter<typeof AdvancedWalletManagerApiSpec> {
const router = createRouter(AdvancedWalletManagerApiSpec);
const router = createRouter(AdvancedWalletManagerApiSpec, {
decodeErrorFormatter: customDecodeErrorFormatter,
});
// Add middleware
router.use(express.json());
router.use(prepareBitGo(config));
Expand Down
5 changes: 4 additions & 1 deletion src/advancedWalletManager/routers/healthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Response } from '@api-ts/response';
import pjson from '../../../package.json';
import { responseHandler } from '../../shared/middleware';
import { PingResponseType, VersionResponseType } from '../../types/health';
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';

// API Response types
const PingResponse: HttpResponse = {
Expand Down Expand Up @@ -38,7 +39,9 @@ export const HealthCheckApiSpec = apiSpec({

// Create router with handlers
export function createHealthCheckRouter(): WrappedRouter<typeof HealthCheckApiSpec> {
const router = createRouter(HealthCheckApiSpec);
const router = createRouter(HealthCheckApiSpec, {
decodeErrorFormatter: customDecodeErrorFormatter,
});
// Ping endpoint handler
router.post('v1.health.ping', [
responseHandler(() =>
Expand Down
5 changes: 4 additions & 1 deletion src/masterBitgoExpress/routers/awmExpressHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import logger from '../../shared/logger';
import { responseHandler } from '../../shared/middleware';
import { AdvancedWalletManagerClient } from '../clients/advancedWalletManagerClient';
import { PingResponseType, VersionResponseType } from '../../types/health';
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';

// Response type for /ping/advancedWalletManager endpoint
const PingAwmResponse: HttpResponse = {
Expand Down Expand Up @@ -54,7 +55,9 @@ export const AdvancedWalletManagerHealthSpec = apiSpec({
export function createAdvancedWalletManagerHealthRouter(
cfg: MasterExpressConfig,
): WrappedRouter<typeof AdvancedWalletManagerHealthSpec> {
const router = createRouter(AdvancedWalletManagerHealthSpec);
const router = createRouter(AdvancedWalletManagerHealthSpec, {
decodeErrorFormatter: customDecodeErrorFormatter,
});

// Create an instance of awmClient
const awmClient = new AdvancedWalletManagerClient(cfg);
Expand Down
5 changes: 4 additions & 1 deletion src/masterBitgoExpress/routers/healthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Response } from '@api-ts/response';
import pjson from '../../../package.json';
import { responseHandler } from '../../shared/middleware';
import { PingResponseType, VersionResponseType } from '../../types/health';
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';

// API Response types
const PingResponse: HttpResponse = {
Expand Down Expand Up @@ -40,7 +41,9 @@ export const HealthCheckApiSpec = apiSpec({
export function createHealthCheckRouter(
serverType: string,
): WrappedRouter<typeof HealthCheckApiSpec> {
const router = createRouter(HealthCheckApiSpec);
const router = createRouter(HealthCheckApiSpec, {
decodeErrorFormatter: customDecodeErrorFormatter,
});

// Ping endpoint handler
router.post('v1.health.ping', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type WrappedRouter,
} from '@api-ts/typed-express-router';
import express from 'express';
import { customDecodeErrorFormatter } from '../../shared/errorFormatters';
import { MasterExpressConfig } from '../../shared/types';
import * as utxolib from '@bitgo-beta/utxo-lib';
import { prepareBitGo, responseHandler } from '../../shared/middleware';
Expand Down Expand Up @@ -82,7 +83,9 @@ export type GenericMasterApiSpecRouteRequest = MasterApiSpecRouteRequest<any, an
export function createMasterApiRouter(
cfg: MasterExpressConfig,
): WrappedRouter<typeof MasterBitGoExpressApiSpec> {
const router = createRouter(MasterBitGoExpressApiSpec);
const router = createRouter(MasterBitGoExpressApiSpec, {
decodeErrorFormatter: customDecodeErrorFormatter,
});

// Add middleware to all routes
router.use(parseBody);
Expand Down
8 changes: 8 additions & 0 deletions src/shared/errorFormatters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as PathReporter from 'io-ts/lib/PathReporter';
import { DecodeErrorFormatterFn } from '@api-ts/typed-express-router';

export const customDecodeErrorFormatter: DecodeErrorFormatterFn = (errs, _req) => {
const validationErrors = PathReporter.failure(errs);
const validationErrorMessage = validationErrors.join('\n');
return { error: validationErrorMessage };
};