In this project, we'll design an error log format as well as the protocol we'll use to communicate when our system encounters a problem. To manage error log messages, HTTP code, API error code, and trace, we developed the CustomError class. If you want to view a demonstration of what we've done, follow me:
try {
...
if (!error)
throw new NotFoundException(
[Error message],
)
...
} catch (error) {
const trace = {
source: "Function name (Ser)",
}
if (error instanceof CustomError) throw error.wrap(trace)
throw new CustomError(error as Error).wrap(trace)
}
{
"statusCode": 404,
"timestamp": "2022-10-06T10:48:41.519Z",
"path": "/entity/manage/1",
"error": {
"message": "Controller (Con): Service (Ser): Error message",
"metadata": {
"userId": "1"
}
}
}