← Files RivetARCHIVED FILE
node_modules/http-proxy-middleware/dist/plugins/default/error-response-plugin.js
1.22 KB · Nov 5, 2026 · 12:09 UTC
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorResponsePlugin = void 0;
const status_code_1 = require("../../status-code");
const sanitize_1 = require("../../utils/sanitize");
function isResponseLike(obj) {
return obj && typeof obj.writeHead === 'function';
}
function isSocketLike(obj) {
return obj && typeof obj.write === 'function' && !('writeHead' in obj);
}
const errorResponsePlugin = (proxyServer, options) => {
proxyServer.on('error', (err, req, res, target) => {
// Re-throw error. Not recoverable since req & res are empty.
if (!req && !res) {
throw err; // "Error: Must provide a proper URL as target"
}
if (isResponseLike(res)) {
if (!res.headersSent) {
const statusCode = (0, status_code_1.getStatusCode)(err.code);
res.writeHead(statusCode);
}
const host = req.headers && req.headers.host;
res.end(`Error occurred while trying to proxy: ${(0, sanitize_1.sanitize)(host)}${(0, sanitize_1.sanitize)(req.url)}`);
}
else if (isSocketLike(res)) {
res.destroy();
}
});
};
exports.errorResponsePlugin = errorResponsePlugin;
SHA-256: 9eceb02df75d0a2f9c478ce1c6889303f8e9cac3c3aacde564d84dd71dfcb960