1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.errors = exports.Unavailable = exports.BadGateway = exports.NotImplemented = exports.GeneralError = exports.TooManyRequests = exports.Unprocessable = exports.LengthRequired = exports.Gone = exports.Conflict = exports.Timeout = exports.NotAcceptable = exports.MethodNotAllowed = exports.NotFound = exports.Forbidden = exports.PaymentError = exports.NotAuthenticated = exports.BadRequest = exports.FeathersError = void 0;
|
4 | exports.convert = convert;
|
5 | class FeathersError extends Error {
|
6 | constructor(err, name, code, className, _data) {
|
7 | let msg = typeof err === 'string' ? err : 'Error';
|
8 | const properties = {
|
9 | name,
|
10 | code,
|
11 | className,
|
12 | type: 'FeathersError'
|
13 | };
|
14 | if (Array.isArray(_data)) {
|
15 | properties.data = _data;
|
16 | }
|
17 | else if (typeof err === 'object' || _data !== undefined) {
|
18 | const { message, errors, ...rest } = err !== null && typeof err === 'object' ? err : _data;
|
19 | msg = message || msg;
|
20 | properties.errors = errors;
|
21 | properties.data = rest;
|
22 | }
|
23 | super(msg);
|
24 | Object.assign(this, properties);
|
25 | }
|
26 | toJSON() {
|
27 | const result = {
|
28 | name: this.name,
|
29 | message: this.message,
|
30 | code: this.code,
|
31 | className: this.className
|
32 | };
|
33 | if (this.data !== undefined) {
|
34 | result.data = this.data;
|
35 | }
|
36 | if (this.errors !== undefined) {
|
37 | result.errors = this.errors;
|
38 | }
|
39 | return result;
|
40 | }
|
41 | }
|
42 | exports.FeathersError = FeathersError;
|
43 | class BadRequest extends FeathersError {
|
44 | constructor(message, data) {
|
45 | super(message, 'BadRequest', 400, 'bad-request', data);
|
46 | }
|
47 | }
|
48 | exports.BadRequest = BadRequest;
|
49 |
|
50 | class NotAuthenticated extends FeathersError {
|
51 | constructor(message, data) {
|
52 | super(message, 'NotAuthenticated', 401, 'not-authenticated', data);
|
53 | }
|
54 | }
|
55 | exports.NotAuthenticated = NotAuthenticated;
|
56 |
|
57 | class PaymentError extends FeathersError {
|
58 | constructor(message, data) {
|
59 | super(message, 'PaymentError', 402, 'payment-error', data);
|
60 | }
|
61 | }
|
62 | exports.PaymentError = PaymentError;
|
63 |
|
64 | class Forbidden extends FeathersError {
|
65 | constructor(message, data) {
|
66 | super(message, 'Forbidden', 403, 'forbidden', data);
|
67 | }
|
68 | }
|
69 | exports.Forbidden = Forbidden;
|
70 |
|
71 | class NotFound extends FeathersError {
|
72 | constructor(message, data) {
|
73 | super(message, 'NotFound', 404, 'not-found', data);
|
74 | }
|
75 | }
|
76 | exports.NotFound = NotFound;
|
77 |
|
78 | class MethodNotAllowed extends FeathersError {
|
79 | constructor(message, data) {
|
80 | super(message, 'MethodNotAllowed', 405, 'method-not-allowed', data);
|
81 | }
|
82 | }
|
83 | exports.MethodNotAllowed = MethodNotAllowed;
|
84 |
|
85 | class NotAcceptable extends FeathersError {
|
86 | constructor(message, data) {
|
87 | super(message, 'NotAcceptable', 406, 'not-acceptable', data);
|
88 | }
|
89 | }
|
90 | exports.NotAcceptable = NotAcceptable;
|
91 |
|
92 | class Timeout extends FeathersError {
|
93 | constructor(message, data) {
|
94 | super(message, 'Timeout', 408, 'timeout', data);
|
95 | }
|
96 | }
|
97 | exports.Timeout = Timeout;
|
98 |
|
99 | class Conflict extends FeathersError {
|
100 | constructor(message, data) {
|
101 | super(message, 'Conflict', 409, 'conflict', data);
|
102 | }
|
103 | }
|
104 | exports.Conflict = Conflict;
|
105 |
|
106 | class Gone extends FeathersError {
|
107 | constructor(message, data) {
|
108 | super(message, 'Gone', 410, 'gone', data);
|
109 | }
|
110 | }
|
111 | exports.Gone = Gone;
|
112 |
|
113 | class LengthRequired extends FeathersError {
|
114 | constructor(message, data) {
|
115 | super(message, 'LengthRequired', 411, 'length-required', data);
|
116 | }
|
117 | }
|
118 | exports.LengthRequired = LengthRequired;
|
119 |
|
120 | class Unprocessable extends FeathersError {
|
121 | constructor(message, data) {
|
122 | super(message, 'Unprocessable', 422, 'unprocessable', data);
|
123 | }
|
124 | }
|
125 | exports.Unprocessable = Unprocessable;
|
126 |
|
127 | class TooManyRequests extends FeathersError {
|
128 | constructor(message, data) {
|
129 | super(message, 'TooManyRequests', 429, 'too-many-requests', data);
|
130 | }
|
131 | }
|
132 | exports.TooManyRequests = TooManyRequests;
|
133 |
|
134 | class GeneralError extends FeathersError {
|
135 | constructor(message, data) {
|
136 | super(message, 'GeneralError', 500, 'general-error', data);
|
137 | }
|
138 | }
|
139 | exports.GeneralError = GeneralError;
|
140 |
|
141 | class NotImplemented extends FeathersError {
|
142 | constructor(message, data) {
|
143 | super(message, 'NotImplemented', 501, 'not-implemented', data);
|
144 | }
|
145 | }
|
146 | exports.NotImplemented = NotImplemented;
|
147 |
|
148 | class BadGateway extends FeathersError {
|
149 | constructor(message, data) {
|
150 | super(message, 'BadGateway', 502, 'bad-gateway', data);
|
151 | }
|
152 | }
|
153 | exports.BadGateway = BadGateway;
|
154 |
|
155 | class Unavailable extends FeathersError {
|
156 | constructor(message, data) {
|
157 | super(message, 'Unavailable', 503, 'unavailable', data);
|
158 | }
|
159 | }
|
160 | exports.Unavailable = Unavailable;
|
161 | exports.errors = {
|
162 | FeathersError,
|
163 | BadRequest,
|
164 | NotAuthenticated,
|
165 | PaymentError,
|
166 | Forbidden,
|
167 | NotFound,
|
168 | MethodNotAllowed,
|
169 | NotAcceptable,
|
170 | Timeout,
|
171 | Conflict,
|
172 | LengthRequired,
|
173 | Unprocessable,
|
174 | TooManyRequests,
|
175 | GeneralError,
|
176 | NotImplemented,
|
177 | BadGateway,
|
178 | Unavailable,
|
179 | 400: BadRequest,
|
180 | 401: NotAuthenticated,
|
181 | 402: PaymentError,
|
182 | 403: Forbidden,
|
183 | 404: NotFound,
|
184 | 405: MethodNotAllowed,
|
185 | 406: NotAcceptable,
|
186 | 408: Timeout,
|
187 | 409: Conflict,
|
188 | 410: Gone,
|
189 | 411: LengthRequired,
|
190 | 422: Unprocessable,
|
191 | 429: TooManyRequests,
|
192 | 500: GeneralError,
|
193 | 501: NotImplemented,
|
194 | 502: BadGateway,
|
195 | 503: Unavailable
|
196 | };
|
197 | function convert(error) {
|
198 | if (!error) {
|
199 | return error;
|
200 | }
|
201 | const FeathersError = exports.errors[error.name];
|
202 | const result = FeathersError
|
203 | ? new FeathersError(error.message, error.data)
|
204 | : new Error(error.message || error);
|
205 | if (typeof error === 'object') {
|
206 | Object.assign(result, error);
|
207 | }
|
208 | return result;
|
209 | }
|
210 |
|
\ | No newline at end of file |