You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ Register as a plugin, optional providing any of the following options:
23
23
24
24
-`hideUnhandledErrors`: If to hide unhandled server errors or returning to the client including stack information. Default is to hide errors when `NODE_ENV` environment variable is `production`.
25
25
-`convertValidationErrors`: Convert validation errors to a structured human readable object. Default is `true`.
26
+
-`convertResponsesValidationErrors`: Convert response validation errors to a structured human readable object. Default is to enable when `NODE_ENV` environment variable is different from `production`.
26
27
27
28
Once registered, the server will use the plugin handlers for all errors (basically, both `setErrorHandler` and `setNotFoundHandler` are called).
28
29
@@ -126,6 +127,38 @@ When hitting `/invalid` it will return the following:
126
127
}
127
128
```
128
129
130
+
## Validation and response validation errors
131
+
132
+
If enabled, response will have status of 400 or 500 (depending on whether the request or response validation failed) and the the body will have the `failedValidations` property.
133
+
134
+
Example of a client validation error:
135
+
136
+
```json
137
+
{
138
+
"statusCode": 400,
139
+
"error": "Bad Request",
140
+
"message": "One or more validations failed trying to process your request.",
141
+
"failedValidations": { "query": { "val": "must match pattern \"ab{2}c\"", "val2": "is not a valid property" } }
142
+
}
143
+
```
144
+
145
+
Example of a response validation error:
146
+
147
+
```json
148
+
{
149
+
"error": "Internal Server Error",
150
+
"message": "The response returned from the endpoint violates its specification for the HTTP status 200.",
151
+
"statusCode": 500,
152
+
"failedValidations": {
153
+
"response": {
154
+
"a": "must be a string",
155
+
"b": "must be present",
156
+
"c": "is not a valid property"
157
+
}
158
+
}
159
+
}
160
+
```
161
+
129
162
## Contributing to fastify-errors-properties
130
163
131
164
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
0 commit comments