@marianmeres/http-utils 1.13.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/error.d.ts +1 -1
- package/dist/index.cjs +6 -5
- package/dist/index.js +6 -5
- package/package.json +1 -1
package/dist/error.d.ts
CHANGED
|
@@ -89,6 +89,6 @@ export declare const HTTP_ERROR: {
|
|
|
89
89
|
BadGateway: typeof BadGateway;
|
|
90
90
|
ServiceUnavailable: typeof ServiceUnavailable;
|
|
91
91
|
};
|
|
92
|
-
export declare const createHttpError: (code: number | string, message?: string | null, body?: string | null, cause?: any) =>
|
|
92
|
+
export declare const createHttpError: (code: number | string, message?: string | null, body?: string | null, cause?: any) => HttpError;
|
|
93
93
|
export declare const getErrorMessage: (e: any, stripErrorPrefix?: boolean) => string;
|
|
94
94
|
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -261,9 +261,8 @@ cause) => {
|
|
|
261
261
|
code = Number(code);
|
|
262
262
|
if (isNaN(code) || !(code >= 400 && code < 600))
|
|
263
263
|
code = fallback.CODE;
|
|
264
|
-
// opinionated
|
|
264
|
+
// opinionated conventions
|
|
265
265
|
body = _maybeJsonParse(body);
|
|
266
|
-
// opinionated convention
|
|
267
266
|
cause = _maybeJsonParse(cause);
|
|
268
267
|
// try to find the well known one, otherwise fallback to generic
|
|
269
268
|
const ctor = _wellKnownCtorMap[`${code}`] ?? HttpError;
|
|
@@ -291,8 +290,8 @@ const getErrorMessage = (e, stripErrorPrefix = true) => {
|
|
|
291
290
|
// e.cause is the standard prop for error details, so should be considered as
|
|
292
291
|
// the most authoritative (if available)
|
|
293
292
|
// "code" and "message" are my own conventions
|
|
294
|
-
cause?.
|
|
295
|
-
cause?.
|
|
293
|
+
cause?.message ||
|
|
294
|
+
cause?.code ||
|
|
296
295
|
(typeof cause === 'string' ? cause : null) ||
|
|
297
296
|
// non-standard "body" is this package's HttpError prop
|
|
298
297
|
body?.error?.message ||
|
|
@@ -302,10 +301,12 @@ const getErrorMessage = (e, stripErrorPrefix = true) => {
|
|
|
302
301
|
e?.message ||
|
|
303
302
|
// the Error class name (e.g. TypeError)
|
|
304
303
|
e?.name ||
|
|
305
|
-
// this should handle (almost) everything else (mainly if e is not
|
|
304
|
+
// this should handle (almost) everything else (mainly if e is not an Error instance)
|
|
306
305
|
e?.toString() ||
|
|
307
306
|
// very last fallback if `toString()` was not available (or returned empty)
|
|
308
307
|
'Unknown Error';
|
|
308
|
+
// ensure we're sending string
|
|
309
|
+
msg = `${msg}`;
|
|
309
310
|
if (stripErrorPrefix) {
|
|
310
311
|
msg = msg.replace(/^[^:]*Error: /, '');
|
|
311
312
|
}
|
package/dist/index.js
CHANGED
|
@@ -259,9 +259,8 @@ cause) => {
|
|
|
259
259
|
code = Number(code);
|
|
260
260
|
if (isNaN(code) || !(code >= 400 && code < 600))
|
|
261
261
|
code = fallback.CODE;
|
|
262
|
-
// opinionated
|
|
262
|
+
// opinionated conventions
|
|
263
263
|
body = _maybeJsonParse(body);
|
|
264
|
-
// opinionated convention
|
|
265
264
|
cause = _maybeJsonParse(cause);
|
|
266
265
|
// try to find the well known one, otherwise fallback to generic
|
|
267
266
|
const ctor = _wellKnownCtorMap[`${code}`] ?? HttpError;
|
|
@@ -289,8 +288,8 @@ const getErrorMessage = (e, stripErrorPrefix = true) => {
|
|
|
289
288
|
// e.cause is the standard prop for error details, so should be considered as
|
|
290
289
|
// the most authoritative (if available)
|
|
291
290
|
// "code" and "message" are my own conventions
|
|
292
|
-
cause?.
|
|
293
|
-
cause?.
|
|
291
|
+
cause?.message ||
|
|
292
|
+
cause?.code ||
|
|
294
293
|
(typeof cause === 'string' ? cause : null) ||
|
|
295
294
|
// non-standard "body" is this package's HttpError prop
|
|
296
295
|
body?.error?.message ||
|
|
@@ -300,10 +299,12 @@ const getErrorMessage = (e, stripErrorPrefix = true) => {
|
|
|
300
299
|
e?.message ||
|
|
301
300
|
// the Error class name (e.g. TypeError)
|
|
302
301
|
e?.name ||
|
|
303
|
-
// this should handle (almost) everything else (mainly if e is not
|
|
302
|
+
// this should handle (almost) everything else (mainly if e is not an Error instance)
|
|
304
303
|
e?.toString() ||
|
|
305
304
|
// very last fallback if `toString()` was not available (or returned empty)
|
|
306
305
|
'Unknown Error';
|
|
306
|
+
// ensure we're sending string
|
|
307
|
+
msg = `${msg}`;
|
|
307
308
|
if (stripErrorPrefix) {
|
|
308
309
|
msg = msg.replace(/^[^:]*Error: /, '');
|
|
309
310
|
}
|