8000 Error data no longer a Promise · core-api/javascript-client@733cb05 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

Commit 733cb05

Browse files
committed
Error data no longer a Promise
1 parent 5f01922 commit 733cb05

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

lib/transports/http.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ class HTTPTransport {
8383

8484
return this.fetch(finalUrl, options)
8585
.then(function (response) {
86-
const data = parseResponse(response, decoders)
87-
if (response.ok) {
88-
return data
89-
} else {
90-
throw new errors.ErrorMessage(response.statusText, data)
91-
}
86+
return parseResponse(response, decoders).then(function (data) {
87+
if (response.ok) {
88+
return data
89+
} else {
90+
const title = response.status + ' ' + response.statusText
91+
const error = new errors.ErrorMessage(title, data)
92+
return Promise.reject(error)
93+
}
94+
})
9295
})
9396
}
9497
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coreapi",
3-
"version": "0.0.16",
3+
"version": "0.0.17",
44
"description": "Javascript client library for Core API",
55
"main": "lib/index.js",
66
"scripts": {

tests/transports/http.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ describe('Test the HTTPTransport', function () {
3232
const link = new document.Link(url, 'get')
3333
const transport = new transports.HTTPTransport(null, testUtils.mockedFetch('ERROR', 'text/html', 500))
3434

35-
expect(transport.action(link, decoders).then(() => {}).catch(() => {})).toThrow()
35+
return transport.action(link, decoders)
36+
.catch(function (result) {
37+
expect(result.message).toEqual('500 BAD REQUEST')
38+
expect(result.content).toEqual('ERROR')
39+
})
3640
})
3741

3842
it('should check the action function of an HTTP transport (json) with query params', function () {

0 commit comments

Comments
 (0)
0