@danypops/vehicle-core 0.12.0 → 0.12.2
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/vehicle-errors.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type VehicleErrorMapping = VehicleErrorClassMapping | VehicleErrorPredica
|
|
|
43
43
|
export interface DefineErrorMappingOptions {
|
|
44
44
|
readonly fallbackCategory?: VehicleFailureCategory;
|
|
45
45
|
readonly fallbackCode?: string;
|
|
46
|
+
readonly fallbackMessage?: string;
|
|
46
47
|
}
|
|
47
48
|
/** Maps reviewed domain errors into wire-safe Vehicle errors while preserving already-mapped failures. */
|
|
48
49
|
export declare function defineErrorMapping(rules: readonly VehicleErrorMapping[], options?: DefineErrorMappingOptions): <T>(run: () => T | Promise<T>) => Promise<T>;
|
package/dist/vehicle-errors.js
CHANGED
|
@@ -8,8 +8,10 @@ export function defineErrorMapping(rules, options = {}) {
|
|
|
8
8
|
if (error instanceof VehicleError)
|
|
9
9
|
throw error;
|
|
10
10
|
const rule = rules.find((candidate) => "errorClass" in candidate ? error instanceof candidate.errorClass : candidate.matches(error));
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const causeMessage = error instanceof Error ? error.message : String(error);
|
|
12
|
+
const message = rule === undefined && options.fallbackMessage !== undefined ? options.fallbackMessage : causeMessage;
|
|
13
|
+
const code = rule === undefined ? (options.fallbackCode ?? "operation-rejected") : (rule.code ?? "operation-rejected");
|
|
14
|
+
throw new VehicleError(code, message, {
|
|
13
15
|
category: rule?.category ?? options.fallbackCategory ?? "validation",
|
|
14
16
|
cause: error,
|
|
15
17
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danypops/vehicle-core",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Vehicle's runtime-neutral wire contract: operation descriptors, schema codecs, failure shapes. Zero runtime dependencies, zero Bun-specific code -- the one thing every Vehicle client and server package depends on.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/vehicle-errors.ts
CHANGED
|
@@ -80,6 +80,7 @@ export type VehicleErrorMapping = VehicleErrorClassMapping | VehicleErrorPredica
|
|
|
80
80
|
export interface DefineErrorMappingOptions {
|
|
81
81
|
readonly fallbackCategory?: VehicleFailureCategory;
|
|
82
82
|
readonly fallbackCode?: string;
|
|
83
|
+
readonly fallbackMessage?: string;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
/** Maps reviewed domain errors into wire-safe Vehicle errors while preserving already-mapped failures. */
|
|
@@ -95,8 +96,10 @@ export function defineErrorMapping(
|
|
|
95
96
|
const rule = rules.find((candidate) =>
|
|
96
97
|
"errorClass" in candidate ? error instanceof candidate.errorClass : candidate.matches(error),
|
|
97
98
|
);
|
|
98
|
-
const
|
|
99
|
-
|
|
99
|
+
const causeMessage = error instanceof Error ? error.message : String(error);
|
|
100
|
+
const message = rule === undefined && options.fallbackMessage !== undefined ? options.fallbackMessage : causeMessage;
|
|
101
|
+
const code = rule === undefined ? (options.fallbackCode ?? "operation-rejected") : (rule.code ?? "operation-rejected");
|
|
102
|
+
throw new VehicleError(code, message, {
|
|
100
103
|
category: rule?.category ?? options.fallbackCategory ?? "validation",
|
|
101
104
|
cause: error,
|
|
102
105
|
});
|