diff --git a/src/http.js b/src/http.js index 3d0b4cfb..106077be 100644 --- a/src/http.js +++ b/src/http.js @@ -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 diff --git a/test/authenticated.js b/test/authenticated.js index 83600f66..948db5dd 100644 --- a/test/authenticated.js +++ b/test/authenticated.js @@ -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)