1
0
Fork 0
mirror of synced 2024-07-05 14:31:17 +12:00

Do not throw error on 204 no content (#12643)

This commit is contained in:
melohagan 2023-12-20 11:02:59 +00:00 committed by GitHub
parent 895c9a9ac3
commit 6adb5cfe79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View file

@ -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 (

View file

@ -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", () => {