#3072 - Display response body and headers for requests that result in non-200 responses. Add test to ensure error and response are merged correctly
This commit is contained in:
@@ -27,9 +27,7 @@ export default class LiveResponse extends React.Component {
|
|||||||
const headers = response.get("headers").toJS()
|
const headers = response.get("headers").toJS()
|
||||||
const notDocumented = response.get("notDocumented")
|
const notDocumented = response.get("notDocumented")
|
||||||
const isError = response.get("error")
|
const isError = response.get("error")
|
||||||
|
const body = response.get("text")
|
||||||
const body = isError ? response.get("response").get("text") : response.get("text")
|
|
||||||
|
|
||||||
const headersKeys = Object.keys(headers)
|
const headersKeys = Object.keys(headers)
|
||||||
const contentType = headers["content-type"]
|
const contentType = headers["content-type"]
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,12 @@ export default {
|
|||||||
[SET_RESPONSE]: (state, { payload: { res, path, method } } ) =>{
|
[SET_RESPONSE]: (state, { payload: { res, path, method } } ) =>{
|
||||||
let result
|
let result
|
||||||
if ( res.error ) {
|
if ( res.error ) {
|
||||||
result = Object.assign({error: true}, res.err)
|
result = Object.assign({
|
||||||
|
error: true,
|
||||||
|
name: res.err.name,
|
||||||
|
message: res.err.message,
|
||||||
|
statusCode: res.err.statusCode
|
||||||
|
}, res.err.response)
|
||||||
} else {
|
} else {
|
||||||
result = res
|
result = res
|
||||||
}
|
}
|
||||||
@@ -86,7 +91,7 @@ export default {
|
|||||||
let newState = state.setIn( [ "responses", path, method ], fromJSOrdered(result) )
|
let newState = state.setIn( [ "responses", path, method ], fromJSOrdered(result) )
|
||||||
|
|
||||||
// ImmutableJS messes up Blob. Needs to reset its value.
|
// ImmutableJS messes up Blob. Needs to reset its value.
|
||||||
if (res.data instanceof win.Blob) {
|
if (win.Blob && res.data instanceof win.Blob) {
|
||||||
newState = newState.setIn( [ "responses", path, method, "text" ], res.data)
|
newState = newState.setIn( [ "responses", path, method, "text" ], res.data)
|
||||||
}
|
}
|
||||||
return newState
|
return newState
|
||||||
|
|||||||
@@ -69,4 +69,56 @@ describe("spec plugin - reducer", function(){
|
|||||||
expect(result.toJS()).toEqual(state.toJS())
|
expect(result.toJS()).toEqual(state.toJS())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("set response value", function() {
|
||||||
|
it("should combine the response and error objects", () => {
|
||||||
|
const setResponse = reducer["spec_set_response"]
|
||||||
|
|
||||||
|
const path = "/pet/post"
|
||||||
|
const method = "POST"
|
||||||
|
|
||||||
|
const state = fromJS({})
|
||||||
|
const result = setResponse(state, {
|
||||||
|
payload: {
|
||||||
|
path: path,
|
||||||
|
method: method,
|
||||||
|
res: {
|
||||||
|
error: true,
|
||||||
|
err: {
|
||||||
|
message: "Not Found",
|
||||||
|
name: "Error",
|
||||||
|
response: {
|
||||||
|
data: "response data",
|
||||||
|
headers: {
|
||||||
|
key: "value"
|
||||||
|
},
|
||||||
|
ok: false,
|
||||||
|
status: 404,
|
||||||
|
statusText: "Not Found"
|
||||||
|
},
|
||||||
|
status: 404,
|
||||||
|
statusCode: 404
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let expectedResult = {
|
||||||
|
error: true,
|
||||||
|
message: "Not Found",
|
||||||
|
name: "Error",
|
||||||
|
data: "response data",
|
||||||
|
headers: {
|
||||||
|
key: "value"
|
||||||
|
},
|
||||||
|
ok: false,
|
||||||
|
status: 404,
|
||||||
|
statusCode: 404,
|
||||||
|
statusText: "Not Found"
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = result.getIn(["responses", path, method]).toJS()
|
||||||
|
expect(response).toEqual(expectedResult)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user