Skip to content

Commit

Permalink
ON-39777 # Fixed json content type handling in fetch handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mymattcarroll committed Apr 22, 2024
1 parent dc9b600 commit ca407b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/http-handlers/FetchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class OneBlinkFetchHandler<T>
}

switch (result.response.headers['content-type']) {
case 'application/json; charset=utf-8':
case 'application/json': {
if (
window.ReadableStream &&
Expand Down
13 changes: 6 additions & 7 deletions src/http-handlers/NodeJsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export class OneBlinkNodeJsHandler<T>
switch (result.response.headers['content-type']) {
case 'application/json; charset=utf-8':
case 'application/json': {
const { Readable } = await import('stream')
const { Readable, consumers } = await import('stream')
if (result.response.body instanceof Readable) {
const { json } = await import('stream/consumers')
this.failResponse = {
statusCode: result.response.statusCode,
message: ((await json(result.response.body)) as FailResponse)
.message,
message: (
(await consumers.json(result.response.body)) as FailResponse
).message,
}
}

Expand All @@ -68,12 +68,11 @@ export class OneBlinkNodeJsHandler<T>
break
}
case 'text/html': {
const { Readable } = await import('stream')
const { Readable, consumers } = await import('stream')
if (result.response.body instanceof Readable) {
const { text } = await import('stream/consumers')
this.failResponse = {
statusCode: result.response.statusCode,
message: await text(result.response.body),
message: await consumers.text(result.response.body),
}
}

Expand Down

0 comments on commit ca407b9

Please sign in to comment.