UNPKG

4.16 kBJavaScriptView Raw
1'use strict';
2
3var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
5function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
8
9function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
10
11exports.BaseError = function (_Error) {
12 _inherits(BaseError, _Error);
13
14 /**
15 * @class BaseError
16 * @constructor
17 * @private
18 * @param {String} code Error code
19 * @param {String} message Error message
20 */
21 function BaseError(code, message) {
22 _classCallCheck(this, BaseError);
23
24 var _this = _possibleConstructorReturn(this, (BaseError.__proto__ || Object.getPrototypeOf(BaseError)).call(this, code + ': ' + message));
25
26 _this.code = code;
27 return _this;
28 }
29
30 _createClass(BaseError, [{
31 key: 'toJSON',
32 value: function toJSON() {
33 return {
34 code: this.code,
35 message: this.message
36 };
37 }
38 }]);
39
40 return BaseError;
41}(Error);
42
43exports.FatalError = function (_exports$BaseError) {
44 _inherits(FatalError, _exports$BaseError);
45
46 /**
47 * Fatal Error. Error code is `"EFATAL"`.
48 * @class FatalError
49 * @constructor
50 * @param {String|Error} data Error object or message
51 */
52 function FatalError(data) {
53 _classCallCheck(this, FatalError);
54
55 var error = typeof data === 'string' ? null : data;
56 var message = error ? error.message : data;
57
58 var _this2 = _possibleConstructorReturn(this, (FatalError.__proto__ || Object.getPrototypeOf(FatalError)).call(this, 'EFATAL', message));
59
60 if (error) _this2.stack = error.stack;
61 return _this2;
62 }
63
64 return FatalError;
65}(exports.BaseError);
66
67exports.ParseError = function (_exports$BaseError2) {
68 _inherits(ParseError, _exports$BaseError2);
69
70 /**
71 * Error during parsing. Error code is `"EPARSE"`.
72 * @class ParseError
73 * @constructor
74 * @param {String} message Error message
75 * @param {http.IncomingMessage} response Server response
76 */
77 function ParseError(message, response) {
78 _classCallCheck(this, ParseError);
79
80 var _this3 = _possibleConstructorReturn(this, (ParseError.__proto__ || Object.getPrototypeOf(ParseError)).call(this, 'EPARSE', message));
81
82 _this3.response = response;
83 return _this3;
84 }
85
86 return ParseError;
87}(exports.BaseError);
88
89exports.TelegramError = function (_exports$BaseError3) {
90 _inherits(TelegramError, _exports$BaseError3);
91
92 /**
93 * Error returned from Telegram. Error code is `"ETELEGRAM"`.
94 * @class TelegramError
95 * @constructor
96 * @param {String} message Error message
97 * @param {http.IncomingMessage} response Server response
98 */
99 function TelegramError(message, response) {
100 _classCallCheck(this, TelegramError);
101
102 var _this4 = _possibleConstructorReturn(this, (TelegramError.__proto__ || Object.getPrototypeOf(TelegramError)).call(this, 'ETELEGRAM', message));
103
104 _this4.response = response;
105 return _this4;
106 }
107
108 return TelegramError;
109}(exports.BaseError);
\No newline at end of file