fetch icon indicating copy to clipboard operation
fetch copied to clipboard

Use Response.json

Open tkrotoff opened this issue 3 years ago • 0 comments

See https://twitter.com/lcasdev/status/1564598435772342272

  • https://developer.mozilla.org/en-US/docs/Web/API/Response/json_static
  • https://caniuse.com/mdn-api_response_json_static
  • https://github.com/WebKit/WebKit/commit/206817f17f39b6de35ea63268b74b750030d574f

Here: https://github.com/tkrotoff/fetch/blob/v0.16.0/src/createHttpError.ts#L30-L34

new Response(JSON.stringify(body), {
  status,
  statusText,
  headers: { 'content-type': jsonMimeType }
})

becomes

Response.json(body, { status, statusText })

tkrotoff avatar Aug 30 '22 14:08 tkrotoff