Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function handleError(req, res, label, error) {
let exchangeId;
try {
exchangeId = getExchangeId(req)
} catch (error) {
exchangeId = '???invalid_token???'
}
console.error(`[${exchangeId}] Error on ${label}`);
console.trace(error)
if (error instanceof ccxt.AuthenticationError) {
res.status(401).send();
} else if (error instanceof ccxt.InvalidNonce || error instanceof ccxtRestErrors.AuthError) {
res.status(403).send();
} else if (error instanceof ccxt.OrderNotFound || error instanceof ccxtRestErrors.UnknownExchangeNameError) {
res.status(404).send();
} else if (error instanceof ccxt.InvalidOrder || error instanceof ccxt.InsufficientFunds) {
res.status(400).send();
} else if (error instanceof ccxt.NotSupported || error instanceof ccxtRestErrors.UnsupportedApiError) {
res.status(501).send();
} else if (error instanceof ccxtRestErrors.BrokenExchangeError) {
res.status(503).send();
} else if (error instanceof ccxt.NetworkError) {
res.status(504).send();
} else {
res.status(500).send();
}