@marianmeres/http-utils 1.13.0 → 1.14.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 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) => BadRequest | Unauthorized | Forbidden | NotFound | MethodNotAllowed | RequestTimeout | Conflict | Gone | UnprocessableContent | ImATeapot | InternalServerError | NotImplemented | BadGateway | ServiceUnavailable;
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 convention
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;
@@ -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 the Error instance)
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
+ // cast to 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 convention
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;
@@ -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 the Error instance)
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
+ // cast to string
307
+ msg = `${msg}`;
307
308
  if (stripErrorPrefix) {
308
309
  msg = msg.replace(/^[^:]*Error: /, '');
309
310
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/http-utils",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "Misc DRY http fetch related helpers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",