@appzmonster/fetch-interceptor
Advanced tools
Comparing version 1.0.4 to 1.0.5
# Change Log - @appzmonster/fetch-interceptor | ||
### 1.0.5 (Sunday, 25 July 2021 02:12:00 GMT) | ||
- Fixed error object thrown from MockRequest interceptor. | ||
- Added network error option to MockRequest interceptor to simulate network error. | ||
- Modified MockRequest interceptor error behaviour to follow Fetch API [spec](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch), resolve all request and only reject TypeError (when request fails to complete). | ||
### 1.0.4 (Wednesday, 30 June 2021 15:57:00 GMT) | ||
@@ -4,0 +10,0 @@ |
@@ -57,3 +57,5 @@ "use strict"; | ||
status: 200, | ||
statusText: 'OK' | ||
statusText: 'OK', | ||
simulateNetworkError: false // To simulate request fail to complete, thus throwing error. | ||
}, mock); | ||
@@ -92,7 +94,17 @@ return _this; | ||
}); | ||
/* | ||
Reference: MDN | ||
The Promise returned from fetch() won’t reject on HTTP error status even | ||
if the response is an HTTP 404 or 500. Instead, as soon as the server responds | ||
with headers, the Promise will resolve normally (with the ok property of the | ||
response set to false if the response isn’t in the range 200–299), and it will | ||
only reject on network failure or if anything prevented the request from completing. | ||
*/ | ||
if (_this2._mock.ok === true) { | ||
if (_this2._mock.simulateNetworkError === true) { | ||
var networkError = new TypeError('Network request failed'); | ||
reject(networkError); | ||
} else { | ||
// Resolve response even if it's an error because the request completed. | ||
resolve(mockResponse); | ||
} else { | ||
reject(mockResponse); | ||
} | ||
@@ -99,0 +111,0 @@ }, _this2._mock.delay); |
{ | ||
"name": "@appzmonster/fetch-interceptor", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Fetch-interceptor is a JavaScript library to enable request interceptor feature on Fetch API. The library extends Fetch API and uses fluent API design to allow chaining of one or multiple request interceptors to a Fetch API request.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45962
463