@venizia/ignis-docs 0.0.8-2 → 0.0.8-3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-docs",
|
|
3
|
-
"version": "0.0.8-
|
|
3
|
+
"version": "0.0.8-3",
|
|
4
4
|
"description": "Interactive documentation site and MCP (Model Context Protocol) server for the Ignis Framework. Includes a VitePress-powered documentation site with guides, API references, and best practices. Ships an MCP server (CLI: ignis-docs-mcp) with 11 tools for AI assistants to search docs, browse source code, verify dependencies, and access real-time framework knowledge. Built with Mastra MCP SDK and Fuse.js fuzzy search.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"devDependencies": {
|
|
130
130
|
"@braintree/sanitize-url": "^7.1.2",
|
|
131
131
|
"@types/bun": "^1.3.14",
|
|
132
|
-
"@venizia/dev-configs": "^0.0.7-
|
|
132
|
+
"@venizia/dev-configs": "^0.0.7-3",
|
|
133
133
|
"eslint": "^10.4.0",
|
|
134
134
|
"prettier": "^3.8.3",
|
|
135
135
|
"tsc-alias": "^1.8.17",
|
|
@@ -60,7 +60,7 @@ Use the correct status code for each error type:
|
|
|
60
60
|
| 503 | `RS_5.ServiceUnavailable` | Service temporarily down |
|
|
61
61
|
|
|
62
62
|
:::tip Automatic Database Error Handling
|
|
63
|
-
Database constraint
|
|
63
|
+
Database errors in SQLSTATE class `22` (data exception) and `23` (integrity constraint — unique, foreign key, not null, check, exclusion) are automatically converted to HTTP 400 by the global error middleware. You don't need to catch these manually. Other classes (e.g. syntax / undefined column) stay 500, and production responses are sanitized — see [Repository Layer Errors](#repository-layer-errors).
|
|
64
64
|
:::
|
|
65
65
|
|
|
66
66
|
## 3. Error Handling Patterns
|
|
@@ -148,7 +148,9 @@ export class UserController extends BaseRestController {
|
|
|
148
148
|
|
|
149
149
|
### Repository Layer Errors
|
|
150
150
|
|
|
151
|
-
Database constraint
|
|
151
|
+
Database errors in SQLSTATE class `22` (data exception) and `23` (integrity constraint — unique, foreign key, not null, check, exclusion) are **automatically handled** by the global error middleware and return HTTP 400. Codes outside those classes (e.g. class `42` undefined column — an application/SQL bug) correctly stay 500.
|
|
152
|
+
|
|
153
|
+
**Non-production** returns the full driver context for debugging:
|
|
152
154
|
|
|
153
155
|
```json
|
|
154
156
|
{
|
|
@@ -158,6 +160,14 @@ Database constraint violations (unique, foreign key, not null, check) are **auto
|
|
|
158
160
|
}
|
|
159
161
|
```
|
|
160
162
|
|
|
163
|
+
:::warning Production sanitizes database internals
|
|
164
|
+
In production the message is the **base message only** — `Detail:` (which echoes row values like emails), `Table:`, and `Constraint:` are stripped, and `details.stack`/`details.cause` are omitted. Unexpected (non-client) database errors and connection failures return a generic `"Internal Server Error"`, so SQL, schema names, and connection host/port never leak. Use `requestId` + server logs to diagnose.
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{ "message": "Unique constraint violation", "statusCode": 400, "requestId": "abc123" }
|
|
168
|
+
```
|
|
169
|
+
:::
|
|
170
|
+
|
|
161
171
|
You don't need to wrap repository calls in try-catch for constraint errors. If you need custom error messages, you can still handle them explicitly:
|
|
162
172
|
|
|
163
173
|
```typescript
|
|
@@ -240,7 +250,9 @@ All errors should follow a consistent format:
|
|
|
240
250
|
interface ErrorResponse {
|
|
241
251
|
statusCode: number;
|
|
242
252
|
message: string;
|
|
253
|
+
messageCode?: string; // stable, localizable code (validation: from params.code or the raw Zod code)
|
|
243
254
|
requestId: string;
|
|
255
|
+
extra?: Record<string, unknown>; // structured context attached via getError(...)
|
|
244
256
|
details?: {
|
|
245
257
|
cause?: Array<{
|
|
246
258
|
path: string;
|
|
@@ -271,16 +283,19 @@ interface ErrorResponse {
|
|
|
271
283
|
}
|
|
272
284
|
|
|
273
285
|
// 422 Validation Error
|
|
286
|
+
// `message`/`messageCode` come from the first failing issue — its `params.code` if the schema set
|
|
287
|
+
// one, otherwise the raw Zod code (e.g. `invalid_type`, `too_small`). The full list stays in `details.cause`.
|
|
274
288
|
{
|
|
275
289
|
"statusCode": 422,
|
|
276
|
-
"message": "
|
|
290
|
+
"message": "Invalid email format",
|
|
291
|
+
"messageCode": "user.email.invalid",
|
|
277
292
|
"requestId": "abc123",
|
|
278
293
|
"details": {
|
|
279
294
|
"cause": [
|
|
280
295
|
{
|
|
281
296
|
"path": "email",
|
|
282
297
|
"message": "Invalid email format",
|
|
283
|
-
"code": "
|
|
298
|
+
"code": "custom"
|
|
284
299
|
}
|
|
285
300
|
]
|
|
286
301
|
}
|
|
@@ -43,14 +43,14 @@ IGNIS provides a collection of built-in middlewares for common application needs
|
|
|
43
43
|
|
|
44
44
|
The error handler middleware catches all unhandled errors in your application and formats them into consistent JSON responses.
|
|
45
45
|
|
|
46
|
-
**File:** `packages/core/src/base/middlewares/app-error.middleware.ts`
|
|
46
|
+
**File:** `packages/core/src/base/middlewares/app-error/app-error.middleware.ts`
|
|
47
47
|
|
|
48
48
|
#### Features
|
|
49
49
|
|
|
50
50
|
- **Automatic Error Formatting**: Converts all errors to structured JSON responses
|
|
51
|
-
- **ZodError Support**:
|
|
52
|
-
- **Database Error Handling**:
|
|
53
|
-
- **
|
|
51
|
+
- **ZodError Support**: Validation errors surface a schema-driven `messageCode` and `message` (from `params.code`, else the raw Zod code), with the full per-field list under `details.cause`
|
|
52
|
+
- **Database Error Handling**: Returns 400 for SQLSTATE class `22` (data exception) and `23` (integrity) errors, with a fallback message; other classes (e.g. `42` programming errors) stay 500
|
|
53
|
+
- **Production-Safe**: Hides stack traces, error causes, DB driver internals (`detail`/`table`/`constraint`), and raw system messages in production
|
|
54
54
|
- **Request Tracking**: Includes `requestId` for debugging and tracing
|
|
55
55
|
- **Status Code Detection**: Automatically extracts `statusCode` from errors
|
|
56
56
|
|
|
@@ -87,9 +87,13 @@ app.onError(appErrorHandler({
|
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
**Validation Error (ZodError):**
|
|
90
|
+
|
|
91
|
+
Top-level `message`/`messageCode` come from the first failing issue — its `params.code` if the schema set one (see below), otherwise its raw Zod code. The full per-field list stays under `details.cause`. If `error.rootKey` is configured, the whole body is wrapped under that key.
|
|
92
|
+
|
|
90
93
|
```json
|
|
91
94
|
{
|
|
92
|
-
"message": "
|
|
95
|
+
"message": "Invalid email address",
|
|
96
|
+
"messageCode": "invalid_type",
|
|
93
97
|
"statusCode": 422,
|
|
94
98
|
"requestId": "abc123",
|
|
95
99
|
"details": {
|
|
@@ -100,45 +104,50 @@ app.onError(appErrorHandler({
|
|
|
100
104
|
{
|
|
101
105
|
"path": "email",
|
|
102
106
|
"message": "Invalid email address",
|
|
103
|
-
"code": "
|
|
104
|
-
"expected": "string"
|
|
105
|
-
"received": "undefined"
|
|
107
|
+
"code": "invalid_type",
|
|
108
|
+
"expected": "string"
|
|
106
109
|
}
|
|
107
110
|
]
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
113
|
```
|
|
111
114
|
|
|
115
|
+
To emit a stable, domain-specific `messageCode`, attach `params.code` to a custom check:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
z.string().refine(isEmail, { message: 'Invalid email address', params: { code: 'user.email.invalid' } });
|
|
119
|
+
// → "messageCode": "user.email.invalid"
|
|
120
|
+
```
|
|
121
|
+
|
|
112
122
|
**Database Constraint Error:**
|
|
113
123
|
|
|
114
|
-
Database
|
|
124
|
+
Database errors in SQLSTATE class `22` (data exception) and `23` (integrity constraint) are detected by **class** and returned as 400 Bad Request. A known code uses its specific message; any other in-class code uses `DATABASE_CLIENT_ERROR_FALLBACK_MESSAGE` (`"Invalid database request"`).
|
|
115
125
|
|
|
116
126
|
```json
|
|
127
|
+
// non-production — full driver context for debugging
|
|
117
128
|
{
|
|
118
129
|
"message": "Unique constraint violation\nDetail: Key (email)=(test@example.com) already exists.\nTable: User\nConstraint: UQ_User_email",
|
|
119
130
|
"statusCode": 400,
|
|
120
131
|
"requestId": "abc123",
|
|
121
|
-
"details": {
|
|
122
|
-
"url": "http://localhost:3000/api/users",
|
|
123
|
-
"path": "/api/users",
|
|
124
|
-
"stack": "...", // development only
|
|
125
|
-
"cause": { ... } // development only
|
|
126
|
-
}
|
|
132
|
+
"details": { "url": "...", "path": "/api/users", "stack": "...", "cause": { } }
|
|
127
133
|
}
|
|
128
134
|
```
|
|
129
135
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
|
137
|
-
|
|
138
|
-
|
|
|
139
|
-
|
|
|
140
|
-
|
|
|
141
|
-
|
|
136
|
+
:::warning Production sanitizes database internals
|
|
137
|
+
In **production** the message is the base message only — `Detail:`/`Table:`/`Constraint:` are stripped (they echo row values and schema names), and `details.stack`/`details.cause` are omitted. Codes outside class 22/23 (e.g. `42703` undefined column) and connection failures return a generic `"Internal Server Error"`, so SQL, schema names, and connection host/port never leak.
|
|
138
|
+
:::
|
|
139
|
+
|
|
140
|
+
**Database client error classes** — codes in SQLSTATE class `22` (data exception), `23` (integrity constraint), and `44` (WITH CHECK OPTION) map to HTTP 400. Common codes get a specific message; any other in-class code uses the fallback (`"Invalid database request"`).
|
|
141
|
+
|
|
142
|
+
| Class | Codes with a specific message |
|
|
143
|
+
|-------|-------------------------------|
|
|
144
|
+
| `23` Integrity | `23505` unique · `23503` foreign key · `23502` not null · `23514` check · `23P01` exclusion · `23000` integrity · `23001` restrict |
|
|
145
|
+
| `22` Data exception | `22001` string too long · `22003` numeric range · `22004` null not allowed · `22007` datetime format · `22008` datetime overflow · `22009` tz displacement · `22011` substring · `22012` division by zero · `22023` invalid parameter · `22025` invalid escape · `22026` length mismatch · `22030` duplicate JSON key · `22032` invalid JSON · `22P01` floating-point · `22P02` invalid text · `22P03` invalid binary · `22P05` untranslatable char |
|
|
146
|
+
| `44` View check | `44000` WITH CHECK OPTION violation |
|
|
147
|
+
|
|
148
|
+
:::tip Transient conflicts return 409, not 400/500
|
|
149
|
+
Class `40` (`40001` serialization failure, `40P01` deadlock) is **transient/retryable** and returns **409 Conflict** with `messageCode: "database.conflict"` and a safe "please retry" message — the client can safely retry the same request. Programming/infra classes (`42` syntax, `53` resources, `0A`, `25`, `28`) remain 500.
|
|
150
|
+
:::
|
|
142
151
|
|
|
143
152
|
#### API Reference
|
|
144
153
|
|