From c9f05f21fb96f63bc22359e3b7981cb9b3b727b5 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Mon, 12 Sep 2022 14:48:16 +0300 Subject: [PATCH] feat(fetch): implement Response.error, Response.redirect and Response.error --- .changeset/old-games-impress.md | 5 ++++ packages/fetch/dist/create-node-ponyfill.js | 29 +++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .changeset/old-games-impress.md diff --git a/.changeset/old-games-impress.md b/.changeset/old-games-impress.md new file mode 100644 index 0000000000..cb58109233 --- /dev/null +++ b/.changeset/old-games-impress.md @@ -0,0 +1,5 @@ +--- +'@whatwg-node/fetch': patch +--- + +Add ponyfills for Response.redirect, Response.json and Response.error diff --git a/packages/fetch/dist/create-node-ponyfill.js b/packages/fetch/dist/create-node-ponyfill.js index d3627344c6..a8cefd2009 100644 --- a/packages/fetch/dist/create-node-ponyfill.js +++ b/packages/fetch/dist/create-node-ponyfill.js @@ -319,5 +319,34 @@ module.exports = function createNodePonyfill(opts = {}) { } } + + if (!ponyfills.Response.redirect) { + ponyfills.Response.redirect = function (url, status = 302) { + return new ponyfills.Response(null, { + status, + headers: { + Location: url, + }, + }); + }; + } + if (!ponyfills.Response.json) { + ponyfills.Response.json = function (data, init = {}) { + return new ponyfills.Response(JSON.stringify(data), { + ...init, + headers: { + "Content-Type": "application/json", + ...init.headers, + }, + }); + }; + } + if (!ponyfills.Response.error) { + ponyfills.Response.error = function () { + return new ponyfills.Response(null, { + status: 500, + }); + }; + } return ponyfills; }