Skip to content

Commit 6999eff

Browse files
authored
Refactor error response handling in proxy plugin
Updated error handling to avoid leaking any information of the use of proxy to the client, and preserve more detailed log server-side
1 parent 013dd9b commit 6999eff

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/plugins/default/error-response-plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ export const errorResponsePlugin: Plugin = definePlugin((proxyServer, options) =
2020
if (!req || !res) {
2121
throw err; // "Error: Must provide a proper URL as target"
2222
}
23+
// Log full details server-side where only admins can see them
24+
console.error(`Proxy error for ${req.headers.host}${req.url}:`, err);
2325

26+
// Return generic error to client
2427
if (isResponseLike(res)) {
2528
if (!res.headersSent) {
2629
const statusCode = getStatusCode((err as unknown as any).code);
2730
res.writeHead(statusCode);
2831
}
2932

30-
const host = req.headers && req.headers.host;
31-
res.end(`Error occurred while trying to proxy: ${sanitize(host)}${sanitize(req.url)}`);
33+
res.end('UPSTREAM_ERROR');
3234
} else if (isSocketLike(res)) {
3335
res.destroy();
3436
}

0 commit comments

Comments
 (0)