Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Expose error codes (ViewBlock#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode authored and balthazar committed Mar 6, 2018
1 parent 6647d6d commit 9625e46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const makeQueryString = q =>
const sendResult = call =>
call.then(res => Promise.all([res, res.json()])).then(([res, json]) => {
if (!res.ok) {
throw new Error(json.msg || `${res.status} ${res.statusText}`)
const error = new Error(json.msg || `${res.status} ${res.statusText}`)
error.code = json.code
throw error
}

return json
Expand Down
14 changes: 14 additions & 0 deletions test/authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ test.serial('[REST] tradesHistory', async t => {
t.is(trades.length, 500)
})

test.serial('[REST] error code', async t => {
try {
await client.orderTest({
symbol: 'TRXETH',
side: 'SELL',
type: 'LIMIT',
quantity: '-1337.00000000',
price: '1.00000000',
})
} catch (e) {
t.is(e.code, -1100)
}
})

test.serial('[WS] user', async t => {
const clean = await client.ws.user()
t.truthy(clean)
Expand Down

0 comments on commit 9625e46

Please sign in to comment.