mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 01:02:05 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17fe219773 | ||
|
|
d76c663f25 | ||
|
|
b1655e843e | ||
|
|
af5d44c278 |
@@ -154,16 +154,23 @@ class RouteUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle 429 errors thrown by nginx
|
||||
// Handle 429 errors
|
||||
if (err.error) {
|
||||
// console.log('decodeError: err: ', err)
|
||||
console.log('decodeError: err: ', err)
|
||||
|
||||
// Error thrown by nginx (usually the SLPDB load balancer.)
|
||||
if (err.error.includes('429 Too Many Requests')) {
|
||||
const internalMsg =
|
||||
'429 error thrown by nginx caught by route-utils.js/decodeError()'
|
||||
console.error(internalMsg)
|
||||
wlogger.error(internalMsg)
|
||||
|
||||
return {
|
||||
msg: '429 Too Many Requests',
|
||||
status: 429
|
||||
}
|
||||
} else if (err.error.includes('Too many requests')) {
|
||||
// Error is being thrown by bch-api rate limit middleware.
|
||||
return {
|
||||
msg: '429 Too Many Requests',
|
||||
status: 429
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Unit tests for the route-utils.js library.
|
||||
*/
|
||||
|
||||
const assert = require('chai').assert
|
||||
|
||||
const RouteUtils = require('../../src/util/route-utils.js')
|
||||
|
||||
describe('#route-utils', () => {
|
||||
let uut
|
||||
|
||||
beforeEach(() => {
|
||||
uut = new RouteUtils()
|
||||
})
|
||||
|
||||
describe('#decodeError', () => {
|
||||
it('should decode a 429 error from nginx', () => {
|
||||
const err = {
|
||||
error: '<html>\r\n<head><title>429 Too Many Requests</title></head>\r\n<body>\r\n<center><h1>429 Too Many Requests</h1></center>\r\n<hr><center>nginx/1.18.0 (Ubuntu)</center>\r\n</body>\r\n</html>\r\n',
|
||||
level: 'error',
|
||||
message: 'Error in slp.js/hydrateUtxos().',
|
||||
timestamp: '2021-03-31T04:13:36.662Z'
|
||||
}
|
||||
|
||||
const result = uut.decodeError(err)
|
||||
// console.log('result: ', result)
|
||||
|
||||
assert.property(result, 'msg')
|
||||
assert.equal(result.msg, '429 Too Many Requests')
|
||||
assert.property(result, 'status')
|
||||
assert.equal(result.status, 429)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user