Skip to content

Commit

Permalink
feat(http): add response headers also to reject path
Browse files Browse the repository at this point in the history
Useful e.g. for status code 401 Unauthorized,

which must include a WWW-Authenticate header field.
  • Loading branch information
henri-hulski committed Jan 3, 2017
1 parent 014f7ee commit 2505530
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/cerebral-provider-http/README.md
Expand Up @@ -178,6 +178,7 @@ function someGetAction ({http}) {
.catch((response) => {
response.status // Status code of response
response.result // Parsed response text
response.headers // Parsed response headers
})
}
```
Expand Down
8 changes: 5 additions & 3 deletions packages/cerebral-provider-http/src/DEFAULT_OPTIONS.js
Expand Up @@ -29,10 +29,11 @@ export default {
result = JSON.parse(xhr.responseText)
}

const responseHeaders = 'getAllResponseHeaders' in xhr
? parseHeaders(xhr.getAllResponseHeaders())
: null

if (xhr.status >= 200 && xhr.status < 300) {
const responseHeaders = 'getAllResponseHeaders' in xhr
? parseHeaders(xhr.getAllResponseHeaders())
: null
resolve({
status: xhr.status,
headers: responseHeaders,
Expand All @@ -41,6 +42,7 @@ export default {
} else {
reject({
status: xhr.status,
headers: responseHeaders,
result: result
})
}
Expand Down

0 comments on commit 2505530

Please sign in to comment.