Skip to content

Commit

Permalink
Parse Luno API errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dutu committed May 11, 2020
1 parent 45039d1 commit 5d4243b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.7.1

* Parse Luno API errors

### 1.7.0

* Add getTradeList method
Expand Down
7 changes: 6 additions & 1 deletion lib/BitX.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ BitX.prototype._request = function (method, resourcePath, data, callback) {

res.on('end', function () {
if (res.statusCode !== 200) {
return callback(new Error('BitX error ' + res.statusCode + ': ' + response))
try {
response = JSON.parse(response)
return callback(new Error('luno API error ' + response.error_code + ': ' + response.error))
} catch (err) {
return callback(new Error('luno unknown API error ' + res.statusCode + ': ' + response))
}
}
try {
response = JSON.parse(response)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitx",
"version": "1.7.0",
"version": "1.7.1",
"author": "Brett Ausmeier <[email protected]>",
"description": "A simple wrapper for the Luno API.",
"license": "MIT",
Expand Down

0 comments on commit 5d4243b

Please sign in to comment.