Skip to content

Commit 5d4243b

Browse files
committed
Parse Luno API errors
1 parent 45039d1 commit 5d4243b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 1.7.1
2+
3+
* Parse Luno API errors
4+
15
### 1.7.0
26

37
* Add getTradeList method

lib/BitX.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ BitX.prototype._request = function (method, resourcePath, data, callback) {
6868

6969
res.on('end', function () {
7070
if (res.statusCode !== 200) {
71-
return callback(new Error('BitX error ' + res.statusCode + ': ' + response))
71+
try {
72+
response = JSON.parse(response)
73+
return callback(new Error('luno API error ' + response.error_code + ': ' + response.error))
74+
} catch (err) {
75+
return callback(new Error('luno unknown API error ' + res.statusCode + ': ' + response))
76+
}
7277
}
7378
try {
7479
response = JSON.parse(response)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bitx",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"author": "Brett Ausmeier <brett@ausmeier.co.za>",
55
"description": "A simple wrapper for the Luno API.",
66
"license": "MIT",

0 commit comments

Comments
 (0)