diff --git a/README.md b/README.md index 0523758..dcd1347 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ d3.image("https://example.com/test.png", {crossOrigin: "anonymous"}).then(functi # d3.json(input[, init]) [<>](https://github.com/d3/d3-fetch/blob/master/src/json.js "Source") -Fetches the [JSON](http://json.org) file at the specified *input* URL. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields. +Fetches the [JSON](http://json.org) file at the specified *input* URL. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields. If the server returns a status code of [204 No Content](https://developer.mozilla.org/docs/Web/HTTP/Status/204) or [205 Reset Content](https://developer.mozilla.org/docs/Web/HTTP/Status/205), the promise resolves to `undefined`. # d3.svg(input[, init]) [<>](https://github.com/d3/d3-fetch/blob/master/src/xml.js "Source") diff --git a/src/json.js b/src/json.js index 758141d..25e9798 100644 --- a/src/json.js +++ b/src/json.js @@ -1,5 +1,6 @@ function responseJson(response) { if (!response.ok) throw new Error(response.status + " " + response.statusText); + if (response.status === 204 || response.status === 205) return; return response.json(); }