Skip to content

Commit 04f4f1f

Browse files
authored
Merge pull request #1622 from OlofMoriya/patch-1
2 parents b6e6bb7 + 05d2609 commit 04f4f1f

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

packages/sdk-middleware-http/src/http.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ export default function createHttpMiddleware({
146146
return
147147
}
148148

149-
res.json().then((result: Object) => {
149+
res.text().then((result: Object) => {
150150
const parsedResponse: Object = {
151151
...response,
152-
body: result,
152+
body: result.length > 0 ? JSON.parse(result) : {},
153153
statusCode: res.status,
154154
}
155155

packages/sdk-middleware-http/test/http.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,4 +952,34 @@ describe('Http', () => {
952952

953953
httpMiddleware(next)(request, response)
954954
}))
955+
956+
test('execute a post request with empty 202 response', () =>
957+
new Promise((resolve, reject) => {
958+
const request = createTestRequest({
959+
uri: '/foo/bar',
960+
method: 'POST',
961+
})
962+
const response = { resolve, reject }
963+
const next = (req, res) => {
964+
expect(res).toEqual({
965+
...response,
966+
body: {},
967+
statusCode: 202,
968+
})
969+
resolve()
970+
}
971+
// Use default options
972+
const httpMiddleware = createHttpMiddleware({
973+
host: testHost,
974+
fetch,
975+
})
976+
nock(testHost)
977+
.defaultReplyHeaders({
978+
'Content-Type': 'application/json',
979+
})
980+
.post('/foo/bar')
981+
.reply(202, undefined)
982+
983+
httpMiddleware(next)(request, response)
984+
}))
955985
})

0 commit comments

Comments
 (0)