backend-error 1.2.0 → 1.2.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.
- package/README.md +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,23 @@ BackendError.Conflict("..."); // 409, showUser: true
|
|
|
81
81
|
BackendError.UnprocessableEntity("..."); // 422, showUser: true
|
|
82
82
|
BackendError.Internal("..."); // 500, showUser: false
|
|
83
83
|
BackendError.ServiceUnavailable("..."); // 503, showUser: false
|
|
84
|
+
BackendError.ExternalAPI("..."); // 502, showUser: true
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### External / upstream errors
|
|
88
|
+
|
|
89
|
+
Use `ExternalAPI` for failures originating from upstream services (Stripe, bank APIs, HR systems etc). It defaults to HTTP `502 Bad Gateway`, `showUser: true` (so the user gets a helpful message), and `severity: "warning"`.
|
|
90
|
+
|
|
91
|
+
Example:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
try {
|
|
95
|
+
// call an external API
|
|
96
|
+
await chargeCard();
|
|
97
|
+
} catch (err) {
|
|
98
|
+
// Indicate the error came from an external API — user can be informed
|
|
99
|
+
throw BackendError.ExternalAPI("Payment provider unavailable"); // 502, showUser: true
|
|
100
|
+
}
|
|
84
101
|
```
|
|
85
102
|
|
|
86
103
|
---
|
|
@@ -109,6 +126,14 @@ app.get("/user/:id", async (req, res) => {
|
|
|
109
126
|
|
|
110
127
|
## 🧩 Types
|
|
111
128
|
|
|
129
|
+
The package re-exports TypeScript types so you get full typings when consuming the package. Import types like this:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import type { BackendErrorOptions, Severity } from "backend-error";
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
For reference, the exported types look like:
|
|
136
|
+
|
|
112
137
|
```ts
|
|
113
138
|
export type Severity = "info" | "warning" | "error" | "critical";
|
|
114
139
|
|
package/package.json
CHANGED