Skip to content

Commit d535001

Browse files
authored
Merge pull request bitpay#2309 from micahriggan/fix/json-parse
Moving JSON parse into try catch
2 parents acd37f8 + 61862a5 commit d535001

File tree

1 file changed

+12
-12
lines changed
  • packages/bitcore-node/src/routes/api

1 file changed

+12
-12
lines changed

packages/bitcore-node/src/routes/api/wallet.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ const authenticate: RequestHandler = async (req: PreAuthRequest, res: Response,
4646
} catch (err) {
4747
return res.status(500).send('Problem authenticating wallet');
4848
}
49-
50-
if (req.is('application/octet-stream')) {
51-
req.body = JSON.parse(req.body.toString());
52-
}
53-
if (!wallet) {
54-
return res.status(404).send('Wallet not found');
55-
}
56-
Object.assign(req, { wallet });
57-
const walletConfig = Config.for('api').wallets;
58-
if (walletConfig && walletConfig.allowUnauthenticatedCalls) {
59-
return next();
60-
}
6149
try {
50+
if (req.is('application/octet-stream')) {
51+
req.body = JSON.parse(req.body.toString());
52+
}
53+
if (!wallet) {
54+
return res.status(404).send('Wallet not found');
55+
}
56+
Object.assign(req, { wallet });
57+
const walletConfig = Config.for('api').wallets;
58+
if (walletConfig && walletConfig.allowUnauthenticatedCalls) {
59+
return next();
60+
}
61+
6262
const validRequestSignature = verifyRequestSignature({
6363
message: [req.method, req.originalUrl, JSON.stringify(req.body)].join('|'),
6464
pubKey: wallet.pubKey,

0 commit comments

Comments
 (0)