bent
Advanced tools
Comparing version 7.3.6 to 7.3.7
{ | ||
"name": "bent", | ||
"version": "7.3.6", | ||
"version": "7.3.7", | ||
"description": "Functional HTTP client for Node.js w/ async/await.", | ||
@@ -5,0 +5,0 @@ "main": "src/nodejs.js", |
@@ -13,3 +13,4 @@ 'use strict' | ||
this.message = `Incorrect statusCode: ${res.status}` | ||
this.name = 'StatusError' | ||
this.message = res.statusMessage | ||
this.statusCode = res.status | ||
@@ -16,0 +17,0 @@ this.res = res |
@@ -51,3 +51,4 @@ 'use strict' | ||
Error.captureStackTrace(this, StatusError) | ||
this.message = `Incorrect statusCode: ${res.statusCode}` | ||
this.name = 'StatusError' | ||
this.message = res.statusMessage | ||
this.statusCode = res.statusCode | ||
@@ -54,0 +55,0 @@ this.json = res.json |
@@ -108,17 +108,34 @@ /* globals atob, it */ | ||
test('status 201', async () => { | ||
const request = bent('string', 201) | ||
const str = await request(u('/echo.js?statusCode=201&body=ok')) | ||
same(str, 'ok') | ||
if (process.browser) { | ||
test('status 201', async () => { | ||
const request = bent('string', 201) | ||
const str = await request(u('/echo.js?statusCode=201&body=ok')) | ||
same(str, 'ok') | ||
try { | ||
await request(u('/echo.js?body=ok')) | ||
throw new Error('Call should have thrown.') | ||
} catch (e) { | ||
same(e.message, 'Incorrect statusCode: 200') | ||
// basic header test | ||
same(e.headers['content-length'], '2') | ||
} | ||
}) | ||
try { | ||
await request(u('/echo.js?body=ok')) | ||
throw new Error('Call should have thrown.') | ||
} catch (e) { | ||
same(e.message, null) | ||
// basic header test | ||
same(e.headers['content-length'], '2') | ||
} | ||
}) | ||
} else { | ||
test('status 201', async () => { | ||
const request = bent('string', 201) | ||
const str = await request(u('/echo.js?statusCode=201&body=ok')) | ||
same(str, 'ok') | ||
try { | ||
await request(u('/echo.js?body=ok')) | ||
throw new Error('Call should have thrown.') | ||
} catch (e) { | ||
same(e.message, 'OK') | ||
// basic header test | ||
same(e.headers['content-length'], '2') | ||
} | ||
}) | ||
} | ||
test('PUT stream', async () => { | ||
@@ -150,24 +167,52 @@ const body = Buffer.from(Math.random().toString()) | ||
test('500 Response body', async () => { | ||
const request = bent() | ||
let body | ||
let _e | ||
try { | ||
await request(u('/echo.js?statusCode=500&body=ok')) | ||
} catch (e) { | ||
_e = e | ||
body = e.responseBody | ||
} | ||
const validate = buffer => { | ||
if (process.browser) { | ||
same(decode(buffer), 'ok') | ||
} else { | ||
same(buffer.toString(), 'ok') | ||
if (process.browser) { | ||
test('500 Response body and message', async () => { | ||
const request = bent() | ||
let body | ||
let _e | ||
try { | ||
await request(u('/echo.js?statusCode=500&body=ok')) | ||
} catch (e) { | ||
_e = e | ||
body = e.responseBody | ||
} | ||
} | ||
validate(await body) | ||
// should be able to access again | ||
validate(await _e.responseBody) | ||
}) | ||
const validate = buffer => { | ||
if (process.browser) { | ||
same(decode(buffer), 'ok') | ||
} else { | ||
same(buffer.toString(), 'ok') | ||
} | ||
} | ||
validate(await body) | ||
// should be able to access again | ||
validate(await _e.responseBody) | ||
same(_e.message, null) | ||
}) | ||
} else { | ||
test('500 Response body and message', async () => { | ||
const request = bent() | ||
let body | ||
let _e | ||
try { | ||
await request(u('/echo.js?statusCode=500&body=ok')) | ||
} catch (e) { | ||
_e = e | ||
body = e.responseBody | ||
} | ||
const validate = buffer => { | ||
if (process.browser) { | ||
same(decode(buffer), 'ok') | ||
} else { | ||
same(buffer.toString(), 'ok') | ||
} | ||
} | ||
validate(await body) | ||
// should be able to access again | ||
validate(await _e.responseBody) | ||
same(_e.message, 'Internal Server Error') | ||
}) | ||
} | ||
test('auth', async () => { | ||
@@ -174,0 +219,0 @@ const request = bent('https://test:pass@httpbin.org/basic-auth/test/pass', 'json') |
26363
667