| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,7 @@ const chunkExpression = common.chunkExpression; | |||
| 35 | 35 | const httpSocketSetup = common.httpSocketSetup; | |
| 36 | 36 | const OutgoingMessage = require('_http_outgoing').OutgoingMessage; | |
| 37 | 37 | const { outHeadersKey, ondrain } = require('internal/http'); | |
| 38 | + const errors = require('internal/errors'); | ||
| 38 | 39 | ||
| 39 | 40 | const STATUS_CODES = { | |
| 40 | 41 | 100: 'Continue', | |
@@ -185,7 +186,9 @@ function writeHead(statusCode, reason, obj) { | |||
| 185 | 186 | ||
| 186 | 187 | statusCode |= 0; | |
| 187 | 188 | if (statusCode < 100 || statusCode > 999) | |
| 188 | - throw new RangeError(`Invalid status code: ${originalStatusCode}`); | ||
| 189 | + throw new errors.RangeError('ERR_HTTP_INVALID_STATUS_CODE', | ||
| 190 | + originalStatusCode); | ||
| 191 | + | ||
| 189 | 192 | ||
| 190 | 193 | if (typeof reason === 'string') { | |
| 191 | 194 | // writeHead(statusCode, reasonPhrase[, headers]) | |
@@ -211,8 +214,7 @@ function writeHead(statusCode, reason, obj) { | |||
| 211 | 214 | } | |
| 212 | 215 | if (k === undefined) { | |
| 213 | 216 | if (this._header) { | |
| 214 | - throw new Error('Can\'t render headers after they are sent to the ' + | ||
| 215 | - 'client'); | ||
| 217 | + throw new errors.Error('ERR_HTTP_HEADERS_SENT'); | ||
| 216 | 218 | } | |
| 217 | 219 | } | |
| 218 | 220 | // only progressive api is used | |
@@ -223,7 +225,8 @@ function writeHead(statusCode, reason, obj) { | |||
| 223 | 225 | } | |
| 224 | 226 | ||
| 225 | 227 | if (common._checkInvalidHeaderChar(this.statusMessage)) | |
| 226 | - throw new Error('Invalid character in statusMessage.'); | ||
| 228 | + throw new errors.Error('ERR_HTTP_INVALID_CHAR', | ||
| 229 | + 'Invalid character in statusMessage.'); | ||
| 227 | 230 | ||
| 228 | 231 | var statusLine = 'HTTP/1.1 ' + statusCode + ' ' + this.statusMessage + CRLF; | |
| 229 | 232 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -114,6 +114,11 @@ E('ERR_ARG_NOT_ITERABLE', '%s must be iterable'); | |||
| 114 | 114 | E('ERR_ASSERTION', (msg) => msg); | |
| 115 | 115 | E('ERR_CONSOLE_WRITABLE_STREAM', | |
| 116 | 116 | (name) => `Console expects a writable stream instance for ${name}`); | |
| 117 | + E('ERR_HTTP_HEADERS_SENT', | ||
| 118 | + 'Cannot render headers after they are sent to the client'); | ||
| 119 | + E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.'); | ||
| 120 | + E('ERR_HTTP_INVALID_STATUS_CODE', | ||
| 121 | + (originalStatusCode) => `Invalid status code: ${originalStatusCode}`); | ||
| 117 | 122 | E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range'); | |
| 118 | 123 | E('ERR_INVALID_ARG_TYPE', invalidArgType); | |
| 119 | 124 | E('ERR_INVALID_CALLBACK', 'callback must be a function'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,11 @@ const MAX_REQUESTS = 13; | |||
| 7 | 7 | let reqNum = 0; | |
| 8 | 8 | ||
| 9 | 9 | function test(res, header, code) { | |
| 10 | - const errRegExp = new RegExp(`^RangeError: Invalid status code: ${code}$`); | ||
| 10 | + const errRegExp = common.expectsError({ | ||
| 11 | + code: 'ERR_HTTP_INVALID_STATUS_CODE', | ||
| 12 | + type: RangeError, | ||
| 13 | + message: `Invalid status code: ${code}` | ||
| 14 | + }); | ||
| 11 | 15 | assert.throws(() => { | |
| 12 | 16 | res.writeHead(header); | |
| 13 | 17 | }, errRegExp); | |
@@ -25,7 +29,7 @@ const server = http.Server(common.mustCall(function(req, res) { | |||
| 25 | 29 | test(res, NaN, 'NaN'); | |
| 26 | 30 | break; | |
| 27 | 31 | case 3: | |
| 28 | - test(res, {}, '\\[object Object\\]'); | ||
| 32 | + test(res, {}, '[object Object]'); | ||
| 29 | 33 | break; | |
| 30 | 34 | case 4: | |
| 31 | 35 | test(res, 99, '99'); | |
@@ -53,7 +57,11 @@ const server = http.Server(common.mustCall(function(req, res) { | |||
| 53 | 57 | break; | |
| 54 | 58 | case 12: | |
| 55 | 59 | assert.throws(() => { res.writeHead(); }, | |
| 56 | - /^RangeError: Invalid status code: undefined$/); | ||
| 60 | + common.expectsError({ | ||
| 61 | + code: 'ERR_HTTP_INVALID_STATUS_CODE', | ||
| 62 | + type: RangeError, | ||
| 63 | + message: 'Invalid status code: undefined' | ||
| 64 | + })); | ||
| 57 | 65 | this.close(); | |
| 58 | 66 | break; | |
| 59 | 67 | default: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,7 +56,12 @@ const s = http.createServer(common.mustCall((req, res) => { | |||
| 56 | 56 | ||
| 57 | 57 | assert.throws(() => { | |
| 58 | 58 | res.writeHead(100, {}); | |
| 59 | - }, /^Error: Can't render headers after they are sent to the client$/); | ||
| 59 | + }, common.expectsError({ | ||
| 60 | + code: 'ERR_HTTP_HEADERS_SENT', | ||
| 61 | + type: Error, | ||
| 62 | + message: 'Cannot render headers after they are sent to the client' | ||
| 63 | + }) | ||
| 64 | + ); | ||
| 60 | 65 | ||
| 61 | 66 | res.end(); | |
| 62 | 67 | })); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments