• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

chimurai / http-proxy-middleware / 23936194070

03 Apr 2026 06:10AM UTC coverage: 96.544% (-0.6%) from 97.15%
23936194070

Pull #1160

github

web-flow
Merge dacea34e5 into 48ed092c3
Pull Request #1160: refactor(#1136): replace `http-proxy` w/ `httpxy`

175 of 191 branches covered (91.62%)

23 of 25 new or added lines in 4 files covered. (92.0%)

1 existing line in 1 file now uncovered.

419 of 434 relevant lines covered (96.54%)

24.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/src/plugins/default/error-response-plugin.ts
1
import type * as http from 'node:http';
2
import type { Socket } from 'node:net';
3

4
import { getStatusCode } from '../../status-code';
12✔
5
import { Plugin } from '../../types';
6
import { sanitize } from '../../utils/sanitize';
12✔
7

8
function isResponseLike(obj: any): obj is http.ServerResponse {
9
  return obj && typeof obj.writeHead === 'function';
2✔
10
}
11

12
function isSocketLike(obj: any): obj is Socket {
13
  return obj && typeof obj.write === 'function' && !('writeHead' in obj);
1✔
14
}
15

16
export const errorResponsePlugin: Plugin = (proxyServer, options) => {
12✔
17
  proxyServer.on('error', (err, req, res, target?) => {
68✔
18
    // Re-throw error. Not recoverable since req & res are empty.
19
    if (!req || !res) {
2!
UNCOV
20
      throw err; // "Error: Must provide a proper URL as target"
×
21
    }
22

23
    if (isResponseLike(res)) {
2✔
24
      if (!res.headersSent) {
1!
25
        const statusCode = getStatusCode((err as unknown as any).code);
1✔
26
        res.writeHead(statusCode);
1✔
27
      }
28

29
      const host = req.headers && req.headers.host;
1✔
30
      res.end(`Error occurred while trying to proxy: ${sanitize(host)}${sanitize(req.url)}`);
1✔
31
    } else if (isSocketLike(res)) {
1!
32
      res.destroy();
1✔
33
    }
34
  });
35
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc