@dnax/core 0.24.1 → 0.24.3

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/app/hono.ts CHANGED
@@ -531,14 +531,19 @@ function HonoInstance(): typeof app {
531
531
  if (err?.code && (err?.code < 200 || err?.code > 599)) {
532
532
  err.code = 409;
533
533
  }
534
+
534
535
  c.status(err.code || 500);
535
- return c.json({
536
+ let errorFormated = {
536
537
  message: err?.message || err,
537
538
  code: err?.code || 500,
538
539
  timestamp: new Date().toISOString(),
539
540
  success: false,
540
541
  meta: err?.meta || {},
541
- });
542
+ };
543
+ if (Cfg.api?.onError && typeof Cfg.api?.onError == "function") {
544
+ await Cfg.api?.onError(errorFormated).catch((err) => {});
545
+ }
546
+ return c.json(errorFormated);
542
547
  }
543
548
  });
544
549
 
@@ -926,7 +926,6 @@ class useRest {
926
926
  let allFieldKeys = getKeyFields(col);
927
927
 
928
928
  if (!col) return fn.error(`Collection ${collection} not found`, 404);
929
- update = toJson(update);
930
929
 
931
930
  if (col?.hooks?.beforeOperation && useHook) {
932
931
  await col.hooks.beforeOperation({
@@ -945,6 +944,7 @@ class useRest {
945
944
  }),
946
945
  });
947
946
  }
947
+ update = toJson(update);
948
948
 
949
949
  if (col?.hooks?.beforeUpdate && useHook) {
950
950
  await col.hooks.beforeUpdate({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.24.1",
3
+ "version": "0.24.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -342,6 +342,12 @@ export type Collection = {
342
342
  }>;
343
343
  };
344
344
 
345
+ interface ApiError {
346
+ code: number;
347
+ message: string;
348
+ meta?: object;
349
+ }
350
+
345
351
  export type loggerFunction = (
346
352
  c: Context,
347
353
  ctx: {
@@ -400,6 +406,9 @@ export type Config = {
400
406
  key: string;
401
407
  };
402
408
  clusterMode?: boolean;
409
+ api?: {
410
+ onError?: (error: ApiError) => Promise<ApiError> | ApiError | void;
411
+ };
403
412
  server: {
404
413
  id?: string;
405
414
  logger?: Boolean | loggerFunction;