1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | if (typeof b !== "function" && b !== null)
|
11 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12 | extendStatics(d, b);
|
13 | function __() { this.constructor = d; }
|
14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15 | };
|
16 | })();
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.InvalidEmailRequestError = exports.InactiveRecipientsError = exports.ApiInputError = exports.UnknownError = exports.RateLimitExceededError = exports.ServiceUnavailablerError = exports.InternalServerError = exports.InvalidAPIKeyError = exports.HttpError = exports.PostmarkError = void 0;
|
19 |
|
20 |
|
21 |
|
22 | var PostmarkError = (function (_super) {
|
23 | __extends(PostmarkError, _super);
|
24 | function PostmarkError(message, code, statusCode) {
|
25 | if (code === void 0) { code = 0; }
|
26 | if (statusCode === void 0) { statusCode = 0; }
|
27 | var _this = _super.call(this, message) || this;
|
28 | _this.statusCode = statusCode;
|
29 | _this.code = code;
|
30 |
|
31 |
|
32 | Object.setPrototypeOf(_this, PostmarkError.prototype);
|
33 | _this.setUpStackTrace();
|
34 | return _this;
|
35 | }
|
36 | PostmarkError.prototype.setUpStackTrace = function () {
|
37 | this.name = this.constructor.name;
|
38 | Error.captureStackTrace(this, this.constructor);
|
39 | };
|
40 | return PostmarkError;
|
41 | }(Error));
|
42 | exports.PostmarkError = PostmarkError;
|
43 | var HttpError = (function (_super) {
|
44 | __extends(HttpError, _super);
|
45 | function HttpError(message, code, statusCode) {
|
46 | var _this = _super.call(this, message, code, statusCode) || this;
|
47 | Object.setPrototypeOf(_this, HttpError.prototype);
|
48 | _this.setUpStackTrace();
|
49 | return _this;
|
50 | }
|
51 | return HttpError;
|
52 | }(PostmarkError));
|
53 | exports.HttpError = HttpError;
|
54 | var InvalidAPIKeyError = (function (_super) {
|
55 | __extends(InvalidAPIKeyError, _super);
|
56 | function InvalidAPIKeyError(message, code, statusCode) {
|
57 | var _this = _super.call(this, message, code, statusCode) || this;
|
58 | Object.setPrototypeOf(_this, InvalidAPIKeyError.prototype);
|
59 | _this.setUpStackTrace();
|
60 | return _this;
|
61 | }
|
62 | return InvalidAPIKeyError;
|
63 | }(HttpError));
|
64 | exports.InvalidAPIKeyError = InvalidAPIKeyError;
|
65 | var InternalServerError = (function (_super) {
|
66 | __extends(InternalServerError, _super);
|
67 | function InternalServerError(message, code, statusCode) {
|
68 | var _this = _super.call(this, message, code, statusCode) || this;
|
69 | Object.setPrototypeOf(_this, InternalServerError.prototype);
|
70 | _this.setUpStackTrace();
|
71 | return _this;
|
72 | }
|
73 | return InternalServerError;
|
74 | }(HttpError));
|
75 | exports.InternalServerError = InternalServerError;
|
76 | var ServiceUnavailablerError = (function (_super) {
|
77 | __extends(ServiceUnavailablerError, _super);
|
78 | function ServiceUnavailablerError(message, code, statusCode) {
|
79 | var _this = _super.call(this, message, code, statusCode) || this;
|
80 | Object.setPrototypeOf(_this, ServiceUnavailablerError.prototype);
|
81 | _this.setUpStackTrace();
|
82 | return _this;
|
83 | }
|
84 | return ServiceUnavailablerError;
|
85 | }(HttpError));
|
86 | exports.ServiceUnavailablerError = ServiceUnavailablerError;
|
87 | var RateLimitExceededError = (function (_super) {
|
88 | __extends(RateLimitExceededError, _super);
|
89 | function RateLimitExceededError(message, code, statusCode) {
|
90 | var _this = _super.call(this, message, code, statusCode) || this;
|
91 | Object.setPrototypeOf(_this, RateLimitExceededError.prototype);
|
92 | _this.setUpStackTrace();
|
93 | return _this;
|
94 | }
|
95 | return RateLimitExceededError;
|
96 | }(HttpError));
|
97 | exports.RateLimitExceededError = RateLimitExceededError;
|
98 | var UnknownError = (function (_super) {
|
99 | __extends(UnknownError, _super);
|
100 | function UnknownError(message, code, statusCode) {
|
101 | var _this = _super.call(this, message, code, statusCode) || this;
|
102 | Object.setPrototypeOf(_this, UnknownError.prototype);
|
103 | _this.setUpStackTrace();
|
104 | return _this;
|
105 | }
|
106 | return UnknownError;
|
107 | }(HttpError));
|
108 | exports.UnknownError = UnknownError;
|
109 | var ApiInputError = (function (_super) {
|
110 | __extends(ApiInputError, _super);
|
111 | function ApiInputError(message, code, statusCode) {
|
112 | var _this = _super.call(this, message, code, statusCode) || this;
|
113 | Object.setPrototypeOf(_this, ApiInputError.prototype);
|
114 | _this.setUpStackTrace();
|
115 | return _this;
|
116 | }
|
117 | ApiInputError.buildSpecificError = function (message, code, statusCode) {
|
118 | switch (code) {
|
119 | case this.ERROR_CODES.inactiveRecipient:
|
120 | return new InactiveRecipientsError(message, code, statusCode);
|
121 | case this.ERROR_CODES.invalidEmailRequest:
|
122 | return new InvalidEmailRequestError(message, code, statusCode);
|
123 | default:
|
124 | return new ApiInputError(message, code, statusCode);
|
125 | }
|
126 | };
|
127 | ApiInputError.ERROR_CODES = {
|
128 | inactiveRecipient: 406,
|
129 | invalidEmailRequest: 300
|
130 | };
|
131 | return ApiInputError;
|
132 | }(HttpError));
|
133 | exports.ApiInputError = ApiInputError;
|
134 | var InactiveRecipientsError = (function (_super) {
|
135 | __extends(InactiveRecipientsError, _super);
|
136 | function InactiveRecipientsError(message, code, statusCode) {
|
137 | var _this = _super.call(this, message, code, statusCode) || this;
|
138 | Object.setPrototypeOf(_this, InactiveRecipientsError.prototype);
|
139 | _this.setUpStackTrace();
|
140 | _this.recipients = InactiveRecipientsError.parseInactiveRecipients(message);
|
141 | return _this;
|
142 | }
|
143 | InactiveRecipientsError.parseInactiveRecipients = function (message) {
|
144 | var result = [];
|
145 | this.inactiveRecipientsPatterns.some(function (pattern) {
|
146 | var regexResult = message.match(pattern);
|
147 | if (regexResult !== null) {
|
148 | result = regexResult[1].split(', ');
|
149 | return result;
|
150 | }
|
151 | else {
|
152 | result = [];
|
153 | }
|
154 | });
|
155 | return result;
|
156 | };
|
157 | InactiveRecipientsError.inactiveRecipientsPatterns = [
|
158 | /Found inactive addresses: (.+?)\.?$/m,
|
159 | /these inactive addresses: (.+?)\. Inactive/,
|
160 | /these inactive addresses: (.+?)\.?$/
|
161 | ];
|
162 | return InactiveRecipientsError;
|
163 | }(ApiInputError));
|
164 | exports.InactiveRecipientsError = InactiveRecipientsError;
|
165 | var InvalidEmailRequestError = (function (_super) {
|
166 | __extends(InvalidEmailRequestError, _super);
|
167 | function InvalidEmailRequestError(message, code, statusCode) {
|
168 | var _this = _super.call(this, message, code, statusCode) || this;
|
169 | Object.setPrototypeOf(_this, InvalidEmailRequestError.prototype);
|
170 | _this.setUpStackTrace();
|
171 | return _this;
|
172 | }
|
173 | return InvalidEmailRequestError;
|
174 | }(ApiInputError));
|
175 | exports.InvalidEmailRequestError = InvalidEmailRequestError;
|
176 |
|
\ | No newline at end of file |