Compare commits

...
4 Commits
Author SHA1 Message Date
Chris Troutner 17fe219773 Merge pull request #126 from Permissionless-Software-Foundation/ct-unstable
fix(error handling): Hanling 429 rate limit error better with hyrateU…
2021-04-01 08:47:44 -08:00
Chris Troutner d76c663f25 fix(error handling): Hanling 429 rate limit error better with hyrateUtxos() 2021-04-01 09:46:33 -07:00
Chris Troutner b1655e843e Merge pull request #125 from Permissionless-Software-Foundation/ct-unstable
fix(route-utils): Adding unit tests for route-utils
2021-03-31 04:06:16 -08:00
Chris Troutner af5d44c278 fix(route-utils): Adding unit tests for route-utils 2021-03-31 05:04:35 -07:00
2 changed files with 43 additions and 2 deletions
+9 -2
View File
@@ -154,16 +154,23 @@ class RouteUtils {
} }
} }
// Handle 429 errors thrown by nginx // Handle 429 errors
if (err.error) { 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')) { if (err.error.includes('429 Too Many Requests')) {
const internalMsg = const internalMsg =
'429 error thrown by nginx caught by route-utils.js/decodeError()' '429 error thrown by nginx caught by route-utils.js/decodeError()'
console.error(internalMsg) console.error(internalMsg)
wlogger.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 { return {
msg: '429 Too Many Requests', msg: '429 Too Many Requests',
status: 429 status: 429
+34
View File
@@ -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)
})
})
})