@dnax/core 0.24.2 → 0.24.4

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
@@ -164,6 +164,11 @@ function HonoInstance(): typeof app {
164
164
  getPermission(session.get()?.role, tenant_id) ||
165
165
  null;
166
166
 
167
+ if (collection && !col?.slug) {
168
+ c.status(404);
169
+ return c.json({ message: `Collection ${collection} not found` });
170
+ }
171
+
167
172
  let nextLifecyle: any = false;
168
173
 
169
174
  // Middleware for apis
@@ -531,14 +536,19 @@ function HonoInstance(): typeof app {
531
536
  if (err?.code && (err?.code < 200 || err?.code > 599)) {
532
537
  err.code = 409;
533
538
  }
539
+
534
540
  c.status(err.code || 500);
535
- return c.json({
541
+ let errorFormated = {
536
542
  message: err?.message || err,
537
543
  code: err?.code || 500,
538
544
  timestamp: new Date().toISOString(),
539
545
  success: false,
540
546
  meta: err?.meta || {},
541
- });
547
+ };
548
+ if (Cfg.api?.onError && typeof Cfg.api?.onError == "function") {
549
+ await Cfg.api?.onError(errorFormated).catch((err: any) => {});
550
+ }
551
+ return c.json(errorFormated);
542
552
  }
543
553
  });
544
554
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.24.2",
3
+ "version": "0.24.4",
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;