@mswjs/interceptors
Advanced tools
Comparing version 0.30.0 to 0.30.1
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkSXGRMPXPjs = require('../../chunk-SXGRMPXP.js'); | ||
var _chunkIJFRWSLWjs = require('../../chunk-IJFRWSLW.js'); | ||
require('../../chunk-MQJ3JOOK.js'); | ||
@@ -8,3 +8,3 @@ require('../../chunk-E4AC7YAC.js'); | ||
exports.ClientRequestInterceptor = _chunkSXGRMPXPjs.ClientRequestInterceptor; | ||
exports.ClientRequestInterceptor = _chunkIJFRWSLWjs.ClientRequestInterceptor; | ||
//# sourceMappingURL=index.js.map |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkSXGRMPXPjs = require('../chunk-SXGRMPXP.js'); | ||
var _chunkIJFRWSLWjs = require('../chunk-IJFRWSLW.js'); | ||
@@ -14,3 +14,3 @@ | ||
var node_default = [ | ||
new (0, _chunkSXGRMPXPjs.ClientRequestInterceptor)(), | ||
new (0, _chunkIJFRWSLWjs.ClientRequestInterceptor)(), | ||
new (0, _chunkAPT7KA3Bjs.XMLHttpRequestInterceptor)() | ||
@@ -17,0 +17,0 @@ ]; |
@@ -6,3 +6,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkSXGRMPXPjs = require('./chunk-SXGRMPXP.js'); | ||
var _chunkIJFRWSLWjs = require('./chunk-IJFRWSLW.js'); | ||
@@ -27,3 +27,3 @@ | ||
interceptors: [ | ||
new (0, _chunkSXGRMPXPjs.ClientRequestInterceptor)(), | ||
new (0, _chunkIJFRWSLWjs.ClientRequestInterceptor)(), | ||
new (0, _chunkAPT7KA3Bjs.XMLHttpRequestInterceptor)() | ||
@@ -30,0 +30,0 @@ ] |
{ | ||
"name": "@mswjs/interceptors", | ||
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.", | ||
"version": "0.30.0", | ||
"version": "0.30.1", | ||
"main": "./lib/node/index.js", | ||
@@ -6,0 +6,0 @@ "module": "./lib/node/index.mjs", |
@@ -291,2 +291,30 @@ [![Latest version](https://img.shields.io/npm/v/@mswjs/interceptors.svg)](https://www.npmjs.com/package/@mswjs/interceptors) | ||
## Error handling | ||
By default, all unhandled exceptions thrown within the `request` listener are coerced to 500 error responses, emulating those exceptions occurring on the actual server. You can listen to the exceptions by adding the `unhandledException` listener to the interceptor: | ||
```js | ||
interceptor.on( | ||
'unhandledException', | ||
({ error, request, requestId, controller }) => { | ||
console.log(error) | ||
} | ||
) | ||
``` | ||
To opt out from the default coercion of unhandled exceptions to server responses, you need to either: | ||
1. Respond to the request with [a mocked response](#mocking-responses) (including error responses); | ||
1. Propagate the error up by throwing it explicitly in the `unhandledException` listener. | ||
Here's an example of propagating the unhandled exception up: | ||
```js | ||
interceptor.on('unhandledException', ({ error }) => { | ||
// Now, any unhandled exception will NOT be coerced to a 500 error response, | ||
// and instead will be thrown during the process execution as-is. | ||
throw error | ||
}) | ||
``` | ||
## WebSocket interception | ||
@@ -541,2 +569,4 @@ | ||
}) | ||
resolver.apply() | ||
``` | ||
@@ -543,0 +573,0 @@ |
@@ -637,10 +637,11 @@ import { ClientRequest, IncomingMessage, STATUS_CODES } from 'node:http' | ||
/** | ||
* @note Some request clients (e.g. Octokit) create a ClientRequest | ||
* in a way that it has no Agent set. Now, whether that's correct is | ||
* @note Some request clients (e.g. Octokit, or proxy providers like | ||
* `global-agent`) create a ClientRequest in a way that it has no Agent set, | ||
* or does not have a destroy method on it. Now, whether that's correct is | ||
* debatable, but we should still handle this case gracefully. | ||
* @see https://github.com/mswjs/interceptors/issues/304 | ||
*/ | ||
// @ts-ignore | ||
this.agent?.destroy() | ||
// @ts-ignore "agent" is a private property. | ||
this.agent?.destroy?.() | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
1168665
15500
579