Skip to content

Commit 3a24291

Browse files
committed
chore(mbe): add better error logging to file
Ticket: WP-5313
1 parent 8165494 commit 3a24291

File tree

10 files changed

+11
-30
lines changed

10 files changed

+11
-30
lines changed

src/api/enclaved/handlers/ecdsaMPCv2Initialize.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export async function ecdsaMPCv2Initialize(
4242
encryptedData,
4343
};
4444
} catch (error) {
45-
logger.debug('Failed to initialize mpc key generation', error);
46-
console.error('Encryption error details:', error);
45+
logger.error('Failed to initialize mpc key generation', error);
4746
throw error;
4847
}
4948
}

src/api/master/handlers/handleSendMany.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
9090
}
9191

9292
const keyIdIndex = params.source === 'user' ? KeyIndices.USER : KeyIndices.BACKUP;
93-
logger.info(`Key ID index: ${keyIdIndex}`);
94-
logger.info(`Key IDs: ${JSON.stringify(wallet.keyIds(), null, 2)}`);
9593

9694
// Get the signing keychains
9795
const signingKeychain = await baseCoin.keychains().get({
@@ -140,8 +138,6 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
140138
reqId,
141139
});
142140

143-
logger.debug('Tx prebuild: %s', JSON.stringify(txPrebuilt, null, 2));
144-
145141
// verify transaction prebuild
146142
try {
147143
const verified = await baseCoin.verifyTransaction({
@@ -163,8 +159,6 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
163159
throw new BadRequestError(`Transaction prebuild failed local validation: ${err.message}`);
164160
}
165161

166-
logger.debug('Tx prebuild: %s', JSON.stringify(txPrebuilt, null, 2));
167-
168162
return signAndSendMultisig(
169163
wallet,
170164
req.decoded.source,

src/api/master/handlers/handleSignAndSendTxRequest.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,11 @@ export async function handleSignAndSendTxRequest(
4141
);
4242
}
4343

44-
logger.debug(`Signing keychain: ${JSON.stringify(signingKeychain, null, 2)}`);
45-
logger.debug(`Params: ${JSON.stringify(params, null, 2)}`);
46-
4744
const txRequest = await getTxRequest(bitgo, wallet.id(), req.params.txRequestId, reqId);
4845
if (!txRequest) {
4946
throw new Error(`TxRequest ${req.params.txRequestId} not found`);
5047
}
5148

52-
logger.debug(`TxRequest: ${JSON.stringify(txRequest, null, 2)}`);
53-
5449
return signAndSendTxRequests(
5550
bitgo,
5651
wallet,

src/api/master/handlers/recoveryConsolidationsWallet.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ export async function handleRecoveryConsolidationsOnPrem(
101101
bitgoKey: bitgoPub,
102102
});
103103

104-
console.log(`Recovery consolidations result: ${JSON.stringify(result)}`);
105-
106104
if (result.transactions) {
107105
txs = result.transactions;
108106
} else if (result.txRequests) {
@@ -111,7 +109,7 @@ export async function handleRecoveryConsolidationsOnPrem(
111109
throw new Error('recoverConsolidations did not return expected transactions');
112110
}
113111

114-
logger.debug(`Found ${txs.length} unsigned consolidation transactions`);
112+
logger.info(`Found ${txs.length} unsigned consolidation transactions`);
115113

116114
const signedTxs = [];
117115
try {

src/api/master/routers/enclavedExpressHealth.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ export function createEnclavedExpressRouter(
8787

8888
router.get('v1.enclaved.version', [
8989
responseHandler(async () => {
90-
logger.debug('Getting version from enclaved express');
91-
9290
try {
9391
// Use the client's getVersion method instead of direct HTTP request
9492
const versionResponse = await enclavedClient.getVersion();

src/enclavedApp.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ export function createBaseUri(config: EnclavedConfig): string {
8989
* Create and configure the express application
9090
*/
9191
export function app(cfg: EnclavedConfig): express.Application {
92-
logger.debug('app is initializing');
92+
logger.info('App is initializing');
9393

9494
const app = express();
9595

9696
setupLogging(app, cfg);
97-
logger.debug('logging setup');
9897

9998
// Add custom morgan token for mTLS client certificate
10099
morgan.token('remote-user', function (req: express.Request) {

src/initConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function configureEnclavedMode(): EnclavedConfig {
154154
throw new Error(`Failed to read TLS key from keyPath: ${err.message}`);
155155
}
156156
} else if (config.tlsKey) {
157-
logger.debug('Using TLS private key from environment variable');
157+
logger.info('Using TLS private key from environment variable');
158158
}
159159

160160
if (!config.tlsCert && config.crtPath) {
@@ -166,7 +166,7 @@ function configureEnclavedMode(): EnclavedConfig {
166166
throw new Error(`Failed to read TLS certificate from crtPath: ${err.message}`);
167167
}
168168
} else if (config.tlsCert) {
169-
logger.debug('Using TLS certificate from environment variable');
169+
logger.info('Using TLS certificate from environment variable');
170170
}
171171

172172
// Validate that certificates are properly loaded when TLS is enabled
@@ -323,7 +323,7 @@ export function configureMasterExpressMode(): MasterExpressConfig {
323323
throw new Error(`Failed to read TLS key from keyPath: ${err.message}`);
324324
}
325325
} else if (config.tlsKey) {
326-
logger.debug('Using TLS private key from environment variable');
326+
logger.info('Using TLS private key from environment variable');
327327
}
328328

329329
if (!config.tlsCert && config.crtPath) {
@@ -335,7 +335,7 @@ export function configureMasterExpressMode(): MasterExpressConfig {
335335
throw new Error(`Failed to read TLS certificate from crtPath: ${err.message}`);
336336
}
337337
} else if (config.tlsCert) {
338-
logger.debug('Using TLS certificate from environment variable');
338+
logger.info('Using TLS certificate from environment variable');
339339
}
340340

341341
// Validate that certificates are properly loaded when TLS is enabled

src/masterExpressApp.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,11 @@ export function createBaseUri(config: MasterExpressConfig): string {
8888
* Create and configure the express application for master express mode
8989
*/
9090
export function app(cfg: MasterExpressConfig): express.Application {
91-
logger.debug('master express app is initializing');
91+
logger.info('Master express app is initializing');
9292

9393
const app = express();
9494

9595
setupLogging(app, cfg);
96-
logger.debug('logging setup');
97-
9896
setupCommonMiddleware(app, cfg);
9997

10098
// Add mTLS middleware before routes if in mTLS mode

src/routes/master.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import express from 'express';
22
import { MasterExpressConfig } from '../shared/types';
33
import { createHealthCheckRouter } from '../api/master/routers/healthCheck';
44
import { createEnclavedExpressRouter } from '../api/master/routers/enclavedExpressHealth';
5-
import logger from '../logger';
65
import { createMasterApiRouter } from '../api/master/routers/masterApiSpec';
76

87
/**
@@ -17,6 +16,4 @@ export function setupRoutes(app: express.Application, cfg: MasterExpressConfig):
1716
app.use(createEnclavedExpressRouter(cfg));
1817

1918
app.use(createMasterApiRouter(cfg));
20-
21-
logger.debug('Master express routes configured');
2219
}

src/shared/responseHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ForbiddenError,
1212
ConflictError,
1313
} from './errors';
14+
import logger from '../logger';
1415

1516
// Extend Express Response to include sendEncoded
1617
interface EncodedResponse extends ExpressResponse {
@@ -41,6 +42,8 @@ export function responseHandler<T extends Config = Config>(fn: ServiceFunction<T
4142
const result = await fn(req as BitGoRequest<T>, res, next);
4243
return res.sendEncoded(result.type, result.payload);
4344
} catch (error) {
45+
logger.error('Error in responseHandler:', error);
46+
4447
// If it's already a Response object (e.g. from Response.error)
4548
if (error && typeof error === 'object' && 'type' in error && 'payload' in error) {
4649
const apiError = error as ApiResponse;

0 commit comments

Comments
 (0)