Skip to content

Commit

Permalink
modify error code&msg, make client cb be called
Browse files Browse the repository at this point in the history
  • Loading branch information
KuthorX authored and aduh95 committed Sep 19, 2023
1 parent 2b0301f commit 37d005a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 19 additions & 5 deletions test/parallel/test-http-client-input-function.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
'use strict';

const common = require('../common');
const http = require('http');
const assert = require('assert');
const ClientRequest = require('http').ClientRequest;

{
const req = new ClientRequest(() => {});
req.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ECONNREFUSED');
const server = http.createServer(common.mustCall((req, res) => {
res.writeHead(200);
res.end('hello world');
})).listen(80, '127.0.0.1');

const req = new ClientRequest(common.mustCall((response) => {
let body = '';
response.setEncoding('utf8');
response.on('data', (chunk) => {
body += chunk;
});

response.on('end', common.mustCall(() => {
assert.strictEqual(body, 'hello world');
server.close();
}));
}));
assert.strictEqual(req.path, '/');
assert.strictEqual(req.method, 'GET');

req.end();
}
3 changes: 2 additions & 1 deletion test/parallel/test-http-client-insecure-http-parser-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ClientRequest = require('http').ClientRequest;
assert.throws(() => {
new ClientRequest({ insecureHTTPParser: 'wrongValue' });
}, {
code: /ERR_INVALID_ARG_TYPE/
code: 'ERR_INVALID_ARG_TYPE',
message: /insecureHTTPParser/
}, 'http request should throw when passing invalid insecureHTTPParser');
}

0 comments on commit 37d005a

Please sign in to comment.