Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle error responses #12

Merged
merged 2 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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