Skip to content

Commit

Permalink
fix(lib): better handling HTTP responses
Browse files Browse the repository at this point in the history
master
  • Loading branch information
Tarcio Saraiva committed Jun 20, 2016
1 parent 2689103 commit 7b07821
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 31 deletions.
20 changes: 12 additions & 8 deletions dist/pact.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/pact.js.map

Large diffs are not rendered by default.

46 changes: 35 additions & 11 deletions dist/pact.web.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/pact.web.js.map

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions src/pact.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@ module.exports = ({consumer, provider}) => {

let interactions = []

function getResponseText (response) {
let responseText = response.text || response.responseText
if (typeof response === 'string' && (typeof responseText === 'undefined')) {
responseText = response
}
return responseText || ''
}

function processResponse (response) {
if (Array.isArray(response)) {
const hasErrors = response
.filter((it) => {
const resp = it.text || it.responseText || ''
return resp.indexOf('interaction_diffs') > -1
})
.map((it) => it.text || it.responseText || '')
.filter((it) => getResponseText(it).indexOf('interaction_diffs') > -1)
.map((it) => getResponseText(it))

if (hasErrors.length) {
return Promise.reject(hasErrors)
} else {
return Promise.resolve(response.map((it) => it.text || it.responseText || ''))
return Promise.resolve(response.map((it) => getResponseText(it)))
}
} else {
let resp = response.text || response.responseText
if (typeof response === 'string' && (typeof resp === 'undefined')) {
resp = response
}
let resp = getResponseText(response)
if (resp.indexOf('interaction_diffs') > -1) {
return Promise.reject(resp)
}
Expand Down

0 comments on commit 7b07821

Please sign in to comment.