node-fetch
Advanced tools
Comparing version 3.2.10 to 3.3.0
@@ -199,2 +199,3 @@ /// <reference types="node" /> | ||
static redirect(url: string, status?: number): Response; | ||
static json(data: any, init?: ResponseInit): Response; | ||
} | ||
@@ -201,0 +202,0 @@ |
{ | ||
"name": "node-fetch", | ||
"version": "3.2.10", | ||
"version": "3.3.0", | ||
"description": "A light-weight module that brings Fetch API to node.js", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -272,4 +272,4 @@ <div align="center"> | ||
class HTTPResponseError extends Error { | ||
constructor(response, ...args) { | ||
super(`HTTP Error Response: ${response.status} ${response.statusText}`, ...args); | ||
constructor(response) { | ||
super(`HTTP Error Response: ${response.status} ${response.statusText}`); | ||
this.response = response; | ||
@@ -404,3 +404,3 @@ } | ||
```js | ||
import fetch { | ||
import fetch, { | ||
Blob, | ||
@@ -407,0 +407,0 @@ blobFrom, |
@@ -127,2 +127,21 @@ /** | ||
static json(data = undefined, init = {}) { | ||
const body = JSON.stringify(data); | ||
if (body === undefined) { | ||
throw new TypeError('data is not JSON serializable'); | ||
} | ||
const headers = new Headers(init && init.headers); | ||
if (!headers.has('content-type')) { | ||
headers.set('content-type', 'application/json'); | ||
} | ||
return new Response(body, { | ||
...init, | ||
headers | ||
}); | ||
} | ||
get [Symbol.toStringTag]() { | ||
@@ -129,0 +148,0 @@ return 'Response'; |
107098
2320