FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScriptSolidServer/src/utils/error-handler.js at patchAppend · bourgeoa/JavaScriptSolidServer · GitHub
bourgeoa
JavaScriptSolidServer
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScriptSolidServer
/
src
/
utils
/
error-handler.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
24 lines (24 loc) · 842 Bytes
Breadcrumbs
JavaScriptSolidServer
/
src
/
utils
/
error-handler.js
Copy path
File metadata and controls
24 lines (24 loc) · 842 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* Top-level Fastify error handler that logs the full stack for any 5xx.
*
* Without this, 500 responses carry only Fastify's default 91-byte body and
* leave no trace in logs — production debugging has to infer the exception
* from the response body alone (see #309 investigation for why that's bad).
*
* 4xx errors carry their own statusCode and don't need stack logging — they
* are expected client errors with self-explanatory messages.
*/
export
function
registerErrorHandler
(
fastify
)
{
fastify
.
setErrorHandler
(
function
(
err
,
request
,
reply
)
{
const
statusCode
=
err
.
statusCode
??
500
;
if
(
statusCode
>=
500
)
{
request
.
log
.
error
(
{
err
,
method
:
request
.
method
,
url
:
request
.
url
,
hostname
:
request
.
hostname
}
,
'Unhandled 5xx error'
)
;
}
reply
.
send
(
err
)
;
}
)
;
}
Back
|
FazBrowse Home
|
New Git URL