| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 631856e commit dc92181
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,7 @@ | |||
| 1 | - // TODO(aduh95): use errors exported by the internal/errors module | ||
| 2 | - /* eslint-disable no-restricted-syntax */ | ||
| 3 | - | ||
| 4 | 1 | 'use strict'; | |
| 5 | 2 | ||
| 6 | 3 | const { | |
| 7 | 4 | ArrayPrototypePush, | |
| 8 | - Error, | ||
| 9 | 5 | ErrorCaptureStackTrace, | |
| 10 | 6 | FunctionPrototypeBind, | |
| 11 | 7 | JSONParse, | |
@@ -15,6 +11,7 @@ const { | |||
| 15 | 11 | } = primordials; | |
| 16 | 12 | ||
| 17 | 13 | const Buffer = require('buffer').Buffer; | |
| 14 | + const { ERR_DEBUGGER_ERROR } = require('internal/errors').codes; | ||
| 18 | 15 | const { EventEmitter } = require('events'); | |
| 19 | 16 | const http = require('http'); | |
| 20 | 17 | const URL = require('url'); | |
@@ -39,7 +36,7 @@ const kEightBytePayloadLengthField = 127; | |||
| 39 | 36 | const kMaskingKeyWidthInBytes = 4; | |
| 40 | 37 | ||
| 41 | 38 | function unpackError({ code, message, data }) { | |
| 42 | - const err = new Error(`${message} - ${data}`); | ||
| 39 | + const err = new ERR_DEBUGGER_ERROR(`${message} - ${data}`); | ||
| 43 | 40 | err.code = code; | |
| 44 | 41 | ErrorCaptureStackTrace(err, unpackError); | |
| 45 | 42 | return err; | |
@@ -101,14 +98,14 @@ function decodeFrameHybi17(data) { | |||
| 101 | 98 | const masked = (secondByte & kMaskBit) !== 0; | |
| 102 | 99 | const compressed = reserved1; | |
| 103 | 100 | if (compressed) { | |
| 104 | - throw new Error('Compressed frames not supported'); | ||
| 101 | + throw new ERR_DEBUGGER_ERROR('Compressed frames not supported'); | ||
| 105 | 102 | } | |
| 106 | 103 | if (!final || reserved2 || reserved3) { | |
| 107 | - throw new Error('Only compression extension is supported'); | ||
| 104 | + throw new ERR_DEBUGGER_ERROR('Only compression extension is supported'); | ||
| 108 | 105 | } | |
| 109 | 106 | ||
| 110 | 107 | if (masked) { | |
| 111 | - throw new Error('Masked server frame - not supported'); | ||
| 108 | + throw new ERR_DEBUGGER_ERROR('Masked server frame - not supported'); | ||
| 112 | 109 | } | |
| 113 | 110 | ||
| 114 | 111 | let closed = false; | |
@@ -119,7 +116,7 @@ function decodeFrameHybi17(data) { | |||
| 119 | 116 | case kOpCodeText: | |
| 120 | 117 | break; | |
| 121 | 118 | default: | |
| 122 | - throw new Error(`Unsupported op code ${opCode}`); | ||
| 119 | + throw new ERR_DEBUGGER_ERROR(`Unsupported op code ${opCode}`); | ||
| 123 | 120 | } | |
| 124 | 121 | ||
| 125 | 122 | let payloadLength = secondByte & kPayloadLengthMask; | |
@@ -183,7 +180,7 @@ class Client extends EventEmitter { | |||
| 183 | 180 | debuglog('< %s', payloadStr); | |
| 184 | 181 | const lastChar = payloadStr[payloadStr.length - 1]; | |
| 185 | 182 | if (payloadStr[0] !== '{' || lastChar !== '}') { | |
| 186 | - throw new Error(`Payload does not look like JSON: ${payloadStr}`); | ||
| 183 | + throw new ERR_DEBUGGER_ERROR(`Payload does not look like JSON: ${payloadStr}`); | ||
| 187 | 184 | } | |
| 188 | 185 | let payload; | |
| 189 | 186 | try { | |
@@ -204,7 +201,7 @@ class Client extends EventEmitter { | |||
| 204 | 201 | this.emit('debugEvent', method, params); | |
| 205 | 202 | this.emit(method, params); | |
| 206 | 203 | } else { | |
| 207 | - throw new Error(`Unsupported response: ${payloadStr}`); | ||
| 204 | + throw new ERR_DEBUGGER_ERROR(`Unsupported response: ${payloadStr}`); | ||
| 208 | 205 | } | |
| 209 | 206 | } | |
| 210 | 207 | } | |
@@ -226,7 +223,7 @@ class Client extends EventEmitter { | |||
| 226 | 223 | callMethod(method, params) { | |
| 227 | 224 | return new Promise((resolve, reject) => { | |
| 228 | 225 | if (!this._socket) { | |
| 229 | - reject(new Error('Use `run` to start the app again.')); | ||
| 226 | + reject(new ERR_DEBUGGER_ERROR('Use `run` to start the app again.')); | ||
| 230 | 227 | return; | |
| 231 | 228 | } | |
| 232 | 229 | const data = { id: ++this._lastId, method, params }; | |
@@ -254,13 +251,13 @@ class Client extends EventEmitter { | |||
| 254 | 251 | function parseChunks() { | |
| 255 | 252 | const resBody = Buffer.concat(chunks).toString(); | |
| 256 | 253 | if (httpRes.statusCode !== 200) { | |
| 257 | - reject(new Error(`Unexpected ${httpRes.statusCode}: ${resBody}`)); | ||
| 254 | + reject(new ERR_DEBUGGER_ERROR(`Unexpected ${httpRes.statusCode}: ${resBody}`)); | ||
| 258 | 255 | return; | |
| 259 | 256 | } | |
| 260 | 257 | try { | |
| 261 | 258 | resolve(JSONParse(resBody)); | |
| 262 | 259 | } catch { | |
| 263 | - reject(new Error(`Response didn't contain JSON: ${resBody}`)); | ||
| 260 | + reject(new ERR_DEBUGGER_ERROR(`Response didn't contain JSON: ${resBody}`)); | ||
| 264 | 261 | ||
| 265 | 262 | } | |
| 266 | 263 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments