errore 0.4.0 → 0.4.1

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 +7 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -180,11 +180,13 @@ async function processOrder(orderId: string): Promise<OrderError | Receipt> {
180
180
  // Caller gets union of all possible errors
181
181
  const receipt = await processOrder('123')
182
182
  if (isError(receipt)) {
183
- matchError(receipt, {
183
+ const message = matchError(receipt, {
184
184
  NotFoundError: e => `Order ${e.id} not found`,
185
185
  ValidationError: e => `Invalid: ${e.field}`,
186
186
  PaymentError: e => `Payment failed: ${e.reason}`,
187
187
  })
188
+ console.log(message)
189
+ return
188
190
  }
189
191
  ```
190
192
 
@@ -229,15 +231,17 @@ class NetworkError extends TaggedError('NetworkError')<{
229
231
  type AppError = ValidationError | NetworkError
230
232
 
231
233
  // Exhaustive matching (TypeScript ensures all cases handled)
232
- matchError(error, {
234
+ const message = matchError(error, {
233
235
  ValidationError: e => `Invalid ${e.field}`,
234
236
  NetworkError: e => `Failed to fetch ${e.url}`
235
237
  })
238
+ console.log(message)
236
239
 
237
240
  // Partial matching with fallback
238
- matchErrorPartial(error, {
241
+ const fallbackMsg = matchErrorPartial(error, {
239
242
  ValidationError: e => `Invalid ${e.field}`
240
243
  }, e => `Unknown error: ${e.message}`)
244
+ console.log(fallbackMsg)
241
245
 
242
246
  // Type guards
243
247
  ValidationError.is(value) // specific class
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "errore",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Type-safe errors as values for TypeScript. Like Go, but with full type inference.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",