Closed zuechai closed 1 year ago
This PR is being deployed to Railway 🚅
admin-portal: ◻️ REMOVED
I triggered the error messages by hitting buttons that I knew would generate error in the PR link. I see the errors show up in the log, which is good, but each shows up twice, which I wasn't expecting. Why is that? Does it get retried automatically? Or something else going on?
@mattsahn Looking into why the errors are printed twice and I think it is happening in the mutationFn()
of Messaging.tsx
in the Client
. I'm going to read through React Query docs to see if that theory makes any sense. I'll also go through the logger configs again to see if there's something I need to change there.
@mattsahn Looking into why the errors are printed twice and I think it is happening in the
mutationFn()
ofMessaging.tsx
in theClient
. I'm going to read through React Query docs to see if that theory makes any sense. I'll also go through the logger configs again to see if there's something I need to change there.
Not a big deal, mostly curious to understand what's happening there. I'm not a frontend dev at all, btw :) @jasoncavanaugh, feel free to jump in and enlighten us and review some code if you're free!
I would have to look more closely at the logs, but react query defaults to retrying fetches when they fail, so that could be why you are seeing multiple error logs consecutively for the same endpoint
Ok, so this has been a mess of a PR. I'm sorry for all my silly mistakes and my confusion.
An alternative for logging errors generally is adding the logger to the error middleware. Then anytime an error is thrown it will be logged by the middleware. Only downside I see is Express doesn't send responses with status 404 to the error handler middleware. This would look something like this:
Otherwise, here are the changes I'm planning to make. I just want to make sure this list is complete and accurate:
logger.error(new Error("message"))
to `logger.error("message")${resp.status} ${MAKE_ERROR_MESSAGE}
from resp.status + " " + MAKE_ERROR_MESSAGE
Let me know your thoughts. Thanks @mattsahn @jasoncavanaugh
Ok, so this has been a mess of a PR. I'm sorry for all my silly mistakes and my confusion.
An alternative for logging errors generally is adding the logger to the error middleware. Then anytime an error is thrown it will be logged by the middleware. Only downside I see is Express doesn't send responses with status 404 to the error handler middleware. This would look something like this:
Otherwise, here are the changes I'm planning to make. I just want to make sure this list is complete and accurate:
- add back throws removed as they were before this PR
- change all
logger.error(new Error("message"))
to `logger.error("message")- change to
${resp.status} ${MAKE_ERROR_MESSAGE}
fromresp.status + " " + MAKE_ERROR_MESSAGE
Let me know your thoughts. Thanks @mattsahn @jasoncavanaugh
Yep this looks good to me! I opened up a separate issue for making the way we throw errors more consistent, so that combined with your changes will probably help a lot
I'm going to close this PR and resubmit a clean branch as the only change that actually needs to be made is adding the logger to the middleware and nothing to messaging.ts
PR for issue #48. It appears to be logging correctly. Right now, the stack is not printed to the log, but that can be easily added if desired.