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
@@ -38,18 +38,25 @@ Can be disabled by setting the `app.disableReplyHelperFunctions` to `true`.
38
38
39
39
Send an error object to the client with message and code. The HTTP status code will be set to statusCode(defaults to 200).
40
40
41
-
Can be disabled by setting the `app.disableApiErrorHandler` to `true`.
42
-
43
-
`throw new ApiError('User Not found', 'err_code_user_not_found', 404, {'error_field':'user'})` will return with http status code 404:
41
+
```javascript
42
+
import { ApiError } from'fastify-app';
43
+
// and in your route handler:
44
+
// ...
45
+
thrownewApiError('User Not found', 'err_code_user_not_found', 404, {'error_field':'user'})
46
+
```
47
+
will return with http status code 404:
44
48
45
49
```json
46
50
{
47
51
"status": "error",
48
52
"message": "User Not found",
49
53
"code": "err_code_user_not_found",
50
-
"error_field": "user"
54
+
"data": {
55
+
"error_field": "username"
56
+
}
51
57
}
52
58
```
59
+
This feature can be disabled by setting the `app.disableApiErrorHandler` to `true`.
53
60
54
61
## Health-checking endpoints
55
62
@@ -81,7 +88,7 @@ By default, the server will add the CORS headers to the response. This behavior
81
88
82
89
### Logging enabled
83
90
84
-
By default, the server will log the request and response to console. This behavior can be disabled by setting the `fastify.disableRequestLogging` to `true`, or by setting the `fastify.logger`. All the settings under the `fastify` key will be passed to the `fastify` construct function.
91
+
By default, the server will log the request and response to console. This behavior can be disabled by setting the `fastify.disableRequestLogging` to `true`. All the settings under the `fastify` key will be passed to the `fastify` construct function.
85
92
86
93
### Log request body and headers
87
94
@@ -95,23 +102,6 @@ By default, the server will log the request body and headers. These behaviors ca
95
102
96
103
By default, the server will send a `Request-Id` header to the client. This behavior can be disabled by setting the `app.disableSendRequestIdHeader` to `true`.
97
104
98
-
### ApiError handler and response
99
-
100
-
By default, if `ApiError(message, code, statusCode, data)` is not caught by local error handler, the server will handle this ApiError and return the error object to the client, with HTTP status code `statusCode` which defaults to `200`.
101
-
102
-
The response format is:
103
-
104
-
```json
105
-
{
106
-
"status": "error",
107
-
"message": "custom error messsage string or object",
108
-
"code": "custom error code",
109
-
"data": "additional data"
110
-
}
111
-
```
112
-
113
-
This behavior can be disabled by setting the `app.disableApiErrorHandler` to `true`.
114
-
115
105
### Other errors handler and default error response
116
106
117
107
By default, the server will handle the uncaught errors and return the error object to the client. The HTTP status code defaults to 200 which also can be changed by settting `app.InternalServerErrorCode`. If `process.env.NODE_ENV === 'development'`, the error detail will be sent to the client.
0 commit comments