diff --git a/lib/utils/Utils.js b/lib/utils/Utils.js index 2ef308bf..76ff94e9 100644 --- a/lib/utils/Utils.js +++ b/lib/utils/Utils.js @@ -4,14 +4,16 @@ const Crypto = require('crypto'); const UserAgent = require('user-agents'); const Flatten = require('flat'); -function InnertubeError(message, info) { - this.info = info || {}; - this.stack = new Error(message).stack; - this.message = message; -} +class InnertubeError extends Error { + constructor (message, info) { + super(message); + + info && (this.info = info); -InnertubeError.prototype = Object.create(Error.prototype); -InnertubeError.prototype.constructor = InnertubeError; + this.date = new Date(); + this.version = require('../../package.json').version; + } +} class ParsingError extends InnertubeError {}; class DownloadError extends InnertubeError {}; @@ -138,7 +140,7 @@ function refineNTokenData(data) { .replace(/""/g, '').replace(/length]\)}"/g, 'length])}'); } -const errors = { UnavailableContentError, ParsingError, DownloadError, InnertubeError, MissingParamError, NoStreamingDataError }; +const errors = { InnertubeError, UnavailableContentError, ParsingError, DownloadError, InnertubeError, MissingParamError, NoStreamingDataError }; const functions = { findNode, getRandomUserAgent, generateSidAuth, generateRandomString, getStringBetweenStrings, camelToSnake, timeToSeconds, refineNTokenData }; module.exports = { ...functions, ...errors }; \ No newline at end of file