Error handling#71
Conversation
|
routes/user.js was used to test the changes. If this is a good candidate to be merged, then we can update all other files, by removing |
|
With respect to error logging. One can either do this //const AppError = require AppError from config/ folder
...
throw new AppError("Missing required fields" , 400);OR
This works, it would be encouraged to use the express response object, if available, to return error responses. return res.status().send({
success: false,
message: 'invalid password or email'
})Instead of this: throw new AppError( 'invalid password or email' , 400);
// OR
throw new Error( 'invalid password or email');This way, we don't get to log unnecessary errors to the file. Yes, `invalid password or email' shouldn't be logged it should be told to the client/user. Note: that this commit handles Unknown exceptions or a known one if thrown as described above. |
In the future, this can be solved....but for now, this is very handy. Yes, you throw errors where do not have access to the express |
|
Hi @ezehlivinus, we don't need to log unnecessary errors related to login/register. Also, we should be able to send errors to the client when the server is down. |
| class AppError extends Error { | ||
| constructor(message, statusCode = 500) { | ||
| super(message); | ||
| this.name = 'Stors'; |
There was a problem hiding this comment.
I think this should be "Storz" instead of "Stors"
Fix/some error fixes
: long date on file-desc
add local time
Code Quality : Linting and formatting
…take care of magicLink errors
|
This Pull Request is due for review and merge. cc/ |
Description
This handled asynchronous errors and other global errors. Try...catch can be omitted. Also, logging errors to files were also implemented. When some unknown error occurs we can keep records of it on logs/*.log files.
The packages,
winstonwas used for logging errors to files, andexpress-async-errorswas used to handle asynchronous errors.Fixes #66 (issue)
Type of change
Checklist: