Do not throw error on 204 no content (#12643)
This commit is contained in:
parent
895c9a9ac3
commit
6adb5cfe79
|
@ -131,7 +131,10 @@ class RestIntegration implements IntegrationBase {
|
||||||
let data, raw, headers
|
let data, raw, headers
|
||||||
const contentType = response.headers.get("content-type") || ""
|
const contentType = response.headers.get("content-type") || ""
|
||||||
try {
|
try {
|
||||||
if (contentType.includes("application/json")) {
|
if (response.status === 204) {
|
||||||
|
data = []
|
||||||
|
raw = []
|
||||||
|
} else if (contentType.includes("application/json")) {
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
raw = JSON.stringify(data)
|
raw = JSON.stringify(data)
|
||||||
} else if (
|
} else if (
|
||||||
|
|
|
@ -186,9 +186,15 @@ describe("REST Integration", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("response", () => {
|
describe("response", () => {
|
||||||
function buildInput(json: any, text: any, header: any) {
|
const contentTypes = ["application/json", "text/plain", "application/xml"]
|
||||||
|
function buildInput(
|
||||||
|
json: any,
|
||||||
|
text: any,
|
||||||
|
header: any,
|
||||||
|
status: number = 200
|
||||||
|
) {
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status,
|
||||||
json: json ? async () => json : undefined,
|
json: json ? async () => json : undefined,
|
||||||
text: text ? async () => text : undefined,
|
text: text ? async () => text : undefined,
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -225,6 +231,18 @@ describe("REST Integration", () => {
|
||||||
expect(output.extra.raw).toEqual(text)
|
expect(output.extra.raw).toEqual(text)
|
||||||
expect(output.extra.headers["content-type"]).toEqual("application/xml")
|
expect(output.extra.headers["content-type"]).toEqual("application/xml")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test.each(contentTypes)(
|
||||||
|
"should not throw an error on 204 no content",
|
||||||
|
async contentType => {
|
||||||
|
const input = buildInput(undefined, null, contentType, 204)
|
||||||
|
const output = await config.integration.parseResponse(input)
|
||||||
|
expect(output.data).toEqual([])
|
||||||
|
expect(output.extra.raw).toEqual([])
|
||||||
|
expect(output.info.code).toEqual(204)
|
||||||
|
expect(output.extra.headers["content-type"]).toEqual(contentType)
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("authentication", () => {
|
describe("authentication", () => {
|
||||||
|
|
Loading…
Reference in New Issue