@arkstack/common 0.14.21 → 0.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/index.d.ts CHANGED
@@ -325,7 +325,8 @@ type ArkstackErrorShape = Error & {
325
325
  errors?: unknown;
326
326
  getModelName?: () => string;
327
327
  status?: number;
328
- statusCode?: number;
328
+ statusCode?: number; /** Custom properties merged into the error response payload. */
329
+ body?: Record<string, unknown>;
329
330
  };
330
331
  interface ArkstackErrorPayload {
331
332
  status: 'error';
@@ -333,6 +334,8 @@ interface ArkstackErrorPayload {
333
334
  message: string;
334
335
  errors?: unknown;
335
336
  stack?: string;
337
+ /** Custom fields contributed by an exception's `body`. */
338
+ [key: string]: unknown;
336
339
  }
337
340
  interface HookRegistry {}
338
341
  type Position = 'before' | 'after' | (string & {});
@@ -534,6 +537,21 @@ declare class AppException extends Exception {
534
537
  [key: string]: string[] | string;
535
538
  } | undefined;
536
539
  statusCode: number;
540
+ /**
541
+ * Custom properties merged into the error response payload.
542
+ *
543
+ * When set, these are merged over the standard error payload (`status`,
544
+ * `code`, `message`, …), letting a subclass add fields to — or reshape — the
545
+ * returned error body.
546
+ *
547
+ * @example
548
+ * ```ts
549
+ * class PaymentException extends AppException {
550
+ * body = { error_code: 'PAYMENT_FAILED', retryable: true }
551
+ * }
552
+ * ```
553
+ */
554
+ body?: Record<string, unknown>;
537
555
  constructor(message?: string, statusCode?: number, options?: ErrorOptions);
538
556
  }
539
557
  //#endregion
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { _ as ConfigLoader, a as env, c as nodeEnv, d as resolveRuntimeDir, f as resolveRuntimeModule, g as CONFIG_KEY, h as envLoader, i as discoverCommands, l as outputDir, m as EnvLoader, n as appUrl, o as importFile, p as toOutputPath, r as config, s as interopDefault, t as appKey, u as rebuildOutput, v as configLoader } from "./system-DUaI4u99.js";
2
- import { _ as Hash, c as abortIf, d as initializeGlobalContext, f as isClass, g as Exception, h as AppException, l as assertFound, m as RequestException, p as perPage, s as abort, u as getModel, v as Encryption } from "./utils-Df3nH1sG.js";
2
+ import { _ as Hash, c as abortIf, d as initializeGlobalContext, f as isClass, g as Exception, h as AppException, l as assertFound, m as RequestException, p as perPage, s as abort, u as getModel, v as Encryption } from "./utils-DLifcZWV.js";
3
3
  import { Hook as Hook$1 } from "@arkstack/foundry";
4
4
  import { Arkstack } from "@arkstack/contract";
5
5
  import { str } from "@h3ravel/support";
@@ -189,6 +189,7 @@ var ErrorHandler = class ErrorHandler {
189
189
  delete payload.errors;
190
190
  delete payload.stack;
191
191
  }
192
+ if (detailedError?.body && typeof detailedError.body === "object") Object.assign(payload, detailedError.body);
192
193
  return payload;
193
194
  }
194
195
  static logUnhandledError(err, request, message) {
@@ -1,2 +1,2 @@
1
- import { _ as Hash, a as use, c as abortIf, d as initializeGlobalContext, f as isClass, i as trait, l as assertFound, n as crc32, o as uses, p as perPage, r as getTraitMethods, s as abort, t as callTraitMethods, u as getModel, v as Encryption } from "../utils-Df3nH1sG.js";
1
+ import { _ as Hash, a as use, c as abortIf, d as initializeGlobalContext, f as isClass, i as trait, l as assertFound, n as crc32, o as uses, p as perPage, r as getTraitMethods, s as abort, t as callTraitMethods, u as getModel, v as Encryption } from "../utils-DLifcZWV.js";
2
2
  export { Encryption, Hash, abort, abortIf, assertFound, callTraitMethods, crc32, getModel, getTraitMethods, initializeGlobalContext, isClass, perPage, trait, use, uses };
@@ -96,6 +96,21 @@ var Exception = class extends Error {
96
96
  var AppException = class extends Exception {
97
97
  errors = void 0;
98
98
  statusCode;
99
+ /**
100
+ * Custom properties merged into the error response payload.
101
+ *
102
+ * When set, these are merged over the standard error payload (`status`,
103
+ * `code`, `message`, …), letting a subclass add fields to — or reshape — the
104
+ * returned error body.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * class PaymentException extends AppException {
109
+ * body = { error_code: 'PAYMENT_FAILED', retryable: true }
110
+ * }
111
+ * ```
112
+ */
113
+ body;
99
114
  constructor(message, statusCode = 400, options) {
100
115
  super(message, options);
101
116
  this.statusCode = statusCode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/common",
3
- "version": "0.14.21",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "description": "Core utilities, primitives, and shared infrastructure for the Arkstack ecosystem.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -45,8 +45,8 @@
45
45
  "peerDependencies": {
46
46
  "@h3ravel/support": "^2.2.0",
47
47
  "arkormx": "^2.10.1",
48
- "@arkstack/contract": "^0.14.21",
49
- "@arkstack/foundry": "^0.14.21"
48
+ "@arkstack/contract": "^0.15.0",
49
+ "@arkstack/foundry": "^0.15.0"
50
50
  },
51
51
  "optionalDependencies": {
52
52
  "@faker-js/faker": "^10.4.0"