Added try/catch to async code to prevent unhandled rejections
This commit is contained in:
parent
fd0cf24c2e
commit
27144ddade
1 changed files with 3105 additions and 3057 deletions
|
|
@ -49,6 +49,7 @@ module.exports = async (
|
|||
mySocketsEvents,
|
||||
{ serverPort, CA, CA_KEY, usetls }
|
||||
) => {
|
||||
try {
|
||||
const { timeout5 } = require('../services/gunDB/contact-api/utils')
|
||||
|
||||
const Http = Axios.create({
|
||||
|
|
@ -650,9 +651,9 @@ module.exports = async (
|
|||
process.env.TRUSTED_KEYS === 'true' || !process.env.TRUSTED_KEYS
|
||||
const trustedKeys = await Storage.get('trustedPKs')
|
||||
// Falls back to true if trusted keys is disabled in .env
|
||||
const [isKeyTrusted = !trustedKeysEnabled] = (trustedKeys || []).filter(
|
||||
trustedKey => trustedKey === publicKey
|
||||
)
|
||||
const [isKeyTrusted = !trustedKeysEnabled] = (
|
||||
trustedKeys || []
|
||||
).filter(trustedKey => trustedKey === publicKey)
|
||||
const walletUnlocked = health.LNDStatus.walletStatus === 'unlocked'
|
||||
const { authorization = '' } = req.headers
|
||||
|
||||
|
|
@ -1483,7 +1484,10 @@ module.exports = async (
|
|||
})
|
||||
} else {
|
||||
res.status(500)
|
||||
res.json({ errorMessage: health.LNDStatus.message, success: false })
|
||||
res.json({
|
||||
errorMessage: health.LNDStatus.message,
|
||||
success: false
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// logger.debug("ListInvoices:", response);
|
||||
|
|
@ -1589,7 +1593,9 @@ module.exports = async (
|
|||
app.post('/api/lnd/decodePayReq', (req, res) => {
|
||||
const { lightning } = LightningServices.services
|
||||
const { payReq } = req.body
|
||||
lightning.decodePayReq({ pay_req: payReq }, async (err, paymentRequest) => {
|
||||
lightning.decodePayReq(
|
||||
{ pay_req: payReq },
|
||||
async (err, paymentRequest) => {
|
||||
if (err) {
|
||||
logger.debug('DecodePayReq Error:', err)
|
||||
const health = await checkHealth()
|
||||
|
|
@ -1606,7 +1612,8 @@ module.exports = async (
|
|||
decodedRequest: paymentRequest
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
app.get('/api/lnd/channelbalance', (req, res) => {
|
||||
|
|
@ -1634,7 +1641,12 @@ module.exports = async (
|
|||
app.post('/api/lnd/openchannel', (req, res) => {
|
||||
const { lightning } = LightningServices.services
|
||||
|
||||
const { pubkey, channelCapacity, channelPushAmount, satPerByte } = req.body
|
||||
const {
|
||||
pubkey,
|
||||
channelCapacity,
|
||||
channelPushAmount,
|
||||
satPerByte
|
||||
} = req.body
|
||||
|
||||
const openChannelRequest = {
|
||||
node_pubkey: Buffer.from(pubkey, 'hex'),
|
||||
|
|
@ -1729,7 +1741,8 @@ module.exports = async (
|
|||
|
||||
if (!feeLimit) {
|
||||
return res.status(400).json({
|
||||
errorMessage: 'please provide a "feeLimit" to the send payment request'
|
||||
errorMessage:
|
||||
'please provide a "feeLimit" to the send payment request'
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -1738,7 +1751,8 @@ module.exports = async (
|
|||
const { dest, amt, finalCltvDelta = 40 } = req.body
|
||||
if (!dest || !amt) {
|
||||
return res.status(400).json({
|
||||
errorMessage: 'please provide "dest" and "amt" for keysend payments'
|
||||
errorMessage:
|
||||
'please provide "dest" and "amt" for keysend payments'
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -1901,7 +1915,10 @@ module.exports = async (
|
|||
app.post('/api/lnd/verifymessage', (req, res) => {
|
||||
const { lightning } = LightningServices.services
|
||||
lightning.verifyMessage(
|
||||
{ msg: Buffer.from(req.body.msg, 'utf8'), signature: req.body.signature },
|
||||
{
|
||||
msg: Buffer.from(req.body.msg, 'utf8'),
|
||||
signature: req.body.signature
|
||||
},
|
||||
async (err, response) => {
|
||||
if (err) {
|
||||
logger.debug('VerifyMessage Error:', err)
|
||||
|
|
@ -2144,7 +2161,9 @@ module.exports = async (
|
|||
logger.info('Error in Chats poll:')
|
||||
logger.error(err)
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: typeof err === 'string' ? err : err.message
|
||||
})
|
||||
|
|
@ -2167,7 +2186,9 @@ module.exports = async (
|
|||
logger.info('Error in Display Name poll:')
|
||||
logger.error(err)
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: typeof err === 'string' ? err : err.message
|
||||
})
|
||||
|
|
@ -2187,7 +2208,9 @@ module.exports = async (
|
|||
logger.info('Error in Handshake Address poll:')
|
||||
logger.error(err)
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: typeof err === 'string' ? err : err.message
|
||||
})
|
||||
|
|
@ -2206,7 +2229,9 @@ module.exports = async (
|
|||
logger.info('Error in BIO poll:')
|
||||
logger.error(err)
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: typeof err === 'string' ? err : err.message
|
||||
})
|
||||
|
|
@ -2803,7 +2828,10 @@ module.exports = async (
|
|||
}
|
||||
}
|
||||
|
||||
ap.get(`/api/gun/${GunEvent.ON_RECEIVED_REQUESTS}`, apiGunRequestsReceivedGet)
|
||||
ap.get(
|
||||
`/api/gun/${GunEvent.ON_RECEIVED_REQUESTS}`,
|
||||
apiGunRequestsReceivedGet
|
||||
)
|
||||
ap.get(`/api/gun/${GunEvent.ON_SENT_REQUESTS}`, apiGunRequestsSentGet)
|
||||
ap.get(`/api/gun/requests/received`, apiGunRequestsReceivedGet)
|
||||
ap.get(`/api/gun/requests/sent`, apiGunRequestsSentGet)
|
||||
|
|
@ -2933,7 +2961,9 @@ module.exports = async (
|
|||
}
|
||||
})
|
||||
|
||||
ap.get(`/api/gun/dev/handshakeNodes/:handshakeAddress`, async (req, res) => {
|
||||
ap.get(
|
||||
`/api/gun/dev/handshakeNodes/:handshakeAddress`,
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { tryAndWait } = require('../services/gunDB/contact-api/utils')
|
||||
|
||||
|
|
@ -2968,7 +2998,8 @@ module.exports = async (
|
|||
errorMessage: err.message
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
ap.get(`/api/gun/dev/user/:publicKey`, async (req, res) => {
|
||||
try {
|
||||
|
|
@ -3146,7 +3177,9 @@ module.exports = async (
|
|||
logger.error('error in rpc once')
|
||||
logger.error(err)
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: err.message
|
||||
})
|
||||
|
|
@ -3170,7 +3203,9 @@ module.exports = async (
|
|||
logger.error('error in rpc load')
|
||||
logger.error(err)
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: err.message
|
||||
})
|
||||
|
|
@ -3194,7 +3229,9 @@ module.exports = async (
|
|||
logger.error('error in rpc once user')
|
||||
logger.error(err)
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: err.message
|
||||
})
|
||||
|
|
@ -3218,7 +3255,9 @@ module.exports = async (
|
|||
logger.error('error in rpc load user')
|
||||
logger.error(err)
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: err.message
|
||||
})
|
||||
|
|
@ -3256,7 +3295,9 @@ module.exports = async (
|
|||
})
|
||||
} catch (err) {
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: err.message
|
||||
})
|
||||
|
|
@ -3304,7 +3345,9 @@ module.exports = async (
|
|||
})
|
||||
} catch (err) {
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: err.message
|
||||
})
|
||||
|
|
@ -3323,7 +3366,9 @@ module.exports = async (
|
|||
})
|
||||
} catch (err) {
|
||||
res
|
||||
.status(err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||
.status(
|
||||
err.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500
|
||||
)
|
||||
.json({
|
||||
errorMessage: err.message
|
||||
})
|
||||
|
|
@ -3405,4 +3450,7 @@ module.exports = async (
|
|||
})
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
logger.warn('Unhandled rejection:', err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue