mielk-api 1.3.5 → 1.3.7

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.
@@ -2,5 +2,5 @@ import { Response } from 'express';
2
2
  import { HttpStatus } from '../types/HttpStatus.js';
3
3
  import { ApiErrorDetails } from '../types/ApiResponse.js';
4
4
  export declare function success<T>(res: Response, status: HttpStatus, data: T): Response<Record<string, any>>;
5
- export declare function failure(res: Response, status: HttpStatus, details: string | ApiErrorDetails): Response<Record<string, any>>;
5
+ export declare function failure(res: Response, status: HttpStatus, details: string | ApiErrorDetails | Error): Response<Record<string, any>>;
6
6
  export declare function serverError(res: Response, err: Error): Response<Record<string, any>>;
@@ -1,4 +1,4 @@
1
- import { isObject, isPrimitive } from 'mielk-fn/variables';
1
+ import { isPrimitive } from 'mielk-fn/variables';
2
2
  import { HttpResponseStatus } from '../httpResponseStatus/HttpResponseStatus.js';
3
3
  import { isProd } from '../../routing/express.js';
4
4
  export function success(res, status, data) {
@@ -9,14 +9,21 @@ export function success(res, status, data) {
9
9
  return res.status(status.code).json(apiResponse);
10
10
  }
11
11
  export function failure(res, status, details) {
12
- const message = isPrimitive(details) ? details : (details === null || details === void 0 ? void 0 : details.message) || status.defaultMessageTag;
12
+ const { message, params } = normalizeErrorDetails(details);
13
13
  const apiError = {
14
14
  success: false,
15
15
  message,
16
- params: isObject(details) ? details.params : undefined
16
+ params
17
17
  };
18
18
  return res.status(status.code).json(apiError);
19
19
  }
20
+ const normalizeErrorDetails = (value) => {
21
+ if (isPrimitive(value))
22
+ return { message: value };
23
+ if (value instanceof Error)
24
+ return { message: value.message };
25
+ return value;
26
+ };
20
27
  export function serverError(res, err) {
21
28
  var _a;
22
29
  const status = HttpResponseStatus.SERVER_ERROR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mielk-api",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "keywords": [],
5
5
  "author": "mielk",
6
6
  "description": "Wrapper for API operations",
@@ -72,12 +72,12 @@
72
72
  "peerDependencies": {
73
73
  "express": "^5",
74
74
  "express-rate-limit": "^8",
75
+ "msnodesqlv8": "^5",
75
76
  "zod": "^4"
76
77
  },
77
78
  "dependencies": {
78
79
  "cors": "^2.8.6",
79
80
  "mielk-fn": "^1.1.1",
80
- "msnodesqlv8": "^5.1.3",
81
81
  "pg": "^8.20.0",
82
82
  "tunnel-ssh": "^5.2.0"
83
83
  }