@nice-code/error 0.5.4 → 0.6.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.
Files changed (2) hide show
  1. package/README.md +18 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -165,6 +165,24 @@ if (err_auth.isExact(caught)) {
165
165
 
166
166
  `castNiceError` handles: `NiceError` instances, serialized JSON objects, native `Error`, error-like objects, nullish values, and primitives.
167
167
 
168
+ ### `castAndHydrate` — cast + narrow + hydrate in one call
169
+
170
+ The idiomatic way to handle an unknown value arriving from a remote boundary when you have a specific domain in mind:
171
+
172
+ ```ts
173
+ import { castAndHydrate } from "@nice-code/error";
174
+
175
+ const error = castAndHydrate(unknownValue, err_auth);
176
+ // → NiceErrorHydrated when it belongs to err_auth, otherwise the raw cast NiceError
177
+
178
+ if (err_auth.isExact(error)) {
179
+ const message = matchFirst(error, {
180
+ invalid_credentials: ({ username }) => `Wrong password for ${username}`,
181
+ account_locked: () => "Account locked",
182
+ });
183
+ }
184
+ ```
185
+
168
186
  ---
169
187
 
170
188
  ## Error handling with handlers
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "module": "build/index.js",
5
5
  "types": "build/types/index.d.ts",
6
6
  "type": "module",
7
- "version": "0.5.4",
7
+ "version": "0.6.0",
8
8
  "exports": {
9
9
  ".": {
10
10
  "source": "./src/index.ts",