aboutsummaryrefslogtreecommitdiff
path: root/node_modules/http2-wrapper/source/utils/errors.js
diff options
context:
space:
mode:
authorMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
committerMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
commitd25e11bee6ca5ca523884da132d18e1400e077b9 (patch)
tree8af39fde19f7ed640a60fb397c7edd647dff1c4c /node_modules/http2-wrapper/source/utils/errors.js
downloadkartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.gz
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.bz2
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.zip
Initial commit
Diffstat (limited to 'node_modules/http2-wrapper/source/utils/errors.js')
-rw-r--r--node_modules/http2-wrapper/source/utils/errors.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/node_modules/http2-wrapper/source/utils/errors.js b/node_modules/http2-wrapper/source/utils/errors.js
new file mode 100644
index 0000000..5018283
--- /dev/null
+++ b/node_modules/http2-wrapper/source/utils/errors.js
@@ -0,0 +1,45 @@
+'use strict';
+/* istanbul ignore file: https://github.com/nodejs/node/blob/master/lib/internal/errors.js */
+
+const makeError = (Base, key, getMessage) => {
+ module.exports[key] = class NodeError extends Base {
+ constructor(...args) {
+ super(typeof getMessage === 'string' ? getMessage : getMessage(args));
+ this.name = `${super.name} [${key}]`;
+ this.code = key;
+ }
+ };
+};
+
+makeError(TypeError, 'ERR_INVALID_ARG_TYPE', args => {
+ const type = args[0].includes('.') ? 'property' : 'argument';
+
+ let valid = args[1];
+ const isManyTypes = Array.isArray(valid);
+
+ if (isManyTypes) {
+ valid = `${valid.slice(0, -1).join(', ')} or ${valid.slice(-1)}`;
+ }
+
+ return `The "${args[0]}" ${type} must be ${isManyTypes ? 'one of' : 'of'} type ${valid}. Received ${typeof args[2]}`;
+});
+
+makeError(TypeError, 'ERR_INVALID_PROTOCOL', args => {
+ return `Protocol "${args[0]}" not supported. Expected "${args[1]}"`;
+});
+
+makeError(Error, 'ERR_HTTP_HEADERS_SENT', args => {
+ return `Cannot ${args[0]} headers after they are sent to the client`;
+});
+
+makeError(TypeError, 'ERR_INVALID_HTTP_TOKEN', args => {
+ return `${args[0]} must be a valid HTTP token [${args[1]}]`;
+});
+
+makeError(TypeError, 'ERR_HTTP_INVALID_HEADER_VALUE', args => {
+ return `Invalid value "${args[0]} for header "${args[1]}"`;
+});
+
+makeError(TypeError, 'ERR_INVALID_CHAR', args => {
+ return `Invalid character in ${args[0]} [${args[1]}]`;
+});