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

Commit 9625e46

Browse files
bennycodebalthazar
authored andcommitted
Expose error codes (ccxt#60)
1 parent 6647d6d commit 9625e46

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/http.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const makeQueryString = q =>
2121
const sendResult = call =>
2222
call.then(res => Promise.all([res, res.json()])).then(([res, json]) => {
2323
if (!res.ok) {
24-
throw new Error(json.msg || `${res.status} ${res.statusText}`)
24+
const error = new Error(json.msg || `${res.status} ${res.statusText}`)
25+
error.code = json.code
26+
throw error
2527
}
2628

2729
return json

test/authenticated.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ test.serial('[REST] tradesHistory', async t => {
128128
t.is(trades.length, 500)
129129
})
130130

131+
test.serial('[REST] error code', async t => {
132+
try {
133+
await client.orderTest({
134+
symbol: 'TRXETH',
135+
side: 'SELL',
136+
type: 'LIMIT',
137+
quantity: '-1337.00000000',
138+
price: '1.00000000',
139+
})
140+
} catch (e) {
141+
t.is(e.code, -1100)
142+
}
143+
})
144+
131145
test.serial('[WS] user', async t => {
132146
const clean = await client.ws.user()
133147
t.truthy(clean)

0 commit comments

Comments
 (0)