Skip to content

Commit

Permalink
Merge pull request #12 from thodges-gh/handle-error-responses
Browse files Browse the repository at this point in the history
Handle error responses
  • Loading branch information
thodges-gh committed Mar 11, 2020
2 parents 9837bd7 + f1761e8 commit 0bd2e67
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cl-gas-updater",
"version": "0.1.0",
"version": "0.1.1",
"description": "A service which updates the gas price for Chainlink responses",
"keywords": [
"chainlink",
Expand Down
2 changes: 1 addition & 1 deletion requester.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getPrice = async (url, speed, multiplyBy) => {
logger.debug(response)
return convertToWei(response[speed], multiplyBy)
} catch (error) {
throw error
logger.error(error)
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const startTestServer = () => {
})
})

app.get('/error', (req, res) => {
res.status(500).send()
})

app.listen(port)
}

Expand Down
20 changes: 20 additions & 0 deletions test/requests_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ describe('createRequests', () => {
})
})

context('when an endpoint returns an error', () => {
const details = {
urls: 'http://localhost:8080/test,http://localhost:8080/error,http://localhost:8080/test',
fields: 'always10Num,always15Num,always20String',
wei: '1000000000,1000000000,1000000000',
fallbackGasPrice: 25000000000,
addedGasPrice: 1000000000,
maxGasPrice: 50000000000

}

const expected = 21000000000

it('returns the expected result', async () => {
const gasPrice = await createRequests(details)
assert.isNumber(gasPrice)
assert.equal(gasPrice, expected)
})
})

after(() => {
testServer.stopTestServer()
})
Expand Down

0 comments on commit 0bd2e67

Please sign in to comment.