-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Centralise frontend network error reporting #3721
Conversation
@krysal interesting in your view on this, in particular, if you have any opinions about this approach. The simpler alternative I can think of was to either copy/paste the conditionals of error handling to the appropriate areas, or to create a similar unified fetch error processing function that just takes Curious for your thoughts regardless! |
Full-stack documentation: https://docs.openverse.org/_preview/3721 Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again. You can check the GitHub pages deployment action list to see the current status of the deployments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach makes sense! I like that we can differentiate the tool the error is sent to for certain kinds of failures.
83c156d
to
e949617
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love centralized recording of errors, and separation of the actionable ones from the non-actionable, @sarayourfriend!
I was thinking whether we should create an Error class for our custom fetchingError instead of an object, in case we need to throw this error somewhere (based on some work in the Nuxt 3 branch). What do you think?
const mediaStore = useMediaStore() | ||
const searchStore = useSearchStore() | ||
const router = useRouter() | ||
const { sendCustomEvent } = useAnalytics() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked that this always works?
The reason that sendCustomEvent
was passed as a parameter here was that you cannot use a composable that requires Nuxt instance outside of setup. There is an edge case useSearch
is called, if I remember correctly, in asyncData
, and Nuxt instance is not available, so a call to useAnalytics
inside useSearch
produces a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. But then should useSearch
return a product based on calling useAnalytics
? I'll revert this change, but that to me sounds like a bit of code smell, if the composable isn't able to call other composables at the top level. Maybe I am misunderstanding the edge case. Either way, I'll remove this from the PR, it definitely doesn't need to be here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the centralization of error management, too! 💯 I think the plugin approach is right; not so sure about the high coupling with Axios since it may go away with Nuxt 3, but it is what it is right now. If we also move the API calls to a plugin, I think the error management will probably merge with it.
In JS you can throw anything. We can wrap it in a class, no problem. But is the idea to be able to check it with |
Thanks for the preliminary reviews, Krystle and Olga. I'll fix up this PR and get it ready for a final review. |
e949617
to
f9c8496
Compare
…eature flag json See note regarding setup-after-env in this section of Jest documentation: https://jestjs.io/docs/jest-object\#jestmockmodulename-factory-options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sendCustomEvent("NETWORK_ERROR", { | ||
requestKind: fetchingError.requestKind, | ||
searchType: fetchingError.searchType, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should treat the 429 errors the same as NETWORK_ERROR
s? There's nothing we can do about them in Sentry, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! Those we can see in Cloudflare, so I don't know how much value we get from sending them to Plausible, but I agree that we can skip them in Sentry 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it's even better, we can completely ignore 429s here :)
@@ -0,0 +1,148 @@ | |||
import { Context } from "@nuxt/types" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we test the$processFetchingError
instead of the plugin itself? This way, the setup and mocking would be simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did start with that, but the function the plugin puts into $processFetchingError
still requires $sentry
and useAnalytics
. It also would require further exporting things from the plugin module that aren't really needed anywhere other to make them testable, and would be testing such small units that it would kind of miss the bigger picture (is how I felt).
Happy to change this if you see a way to make the tests much simpler, and not require mocking $sentry
and useAnalytics
still, but if they still require that, then the only change is one that also additionally tests that the plugin is configured correctly (calls inject
with the right parameters).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly related to this comment, but after spending some time this morning investigating the problems with "search time" event, I realized that this change would also require the changes that would make useAnalytics
usable on the server (see #3775)
I suppose from the function name, but I don't know how to change it. Maybe in breadcrumbs? I'll have to look at the sentry JS docs, but it's a good one to change, absolutely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm requesting changes because I realized that our plausible tracker breaks on the server (it's basically only loaded on the client side). We would need to make sure that the server-side error reporting does not cause new errors. And related to that, we should probably add e2e tests for errors because the unit tests do not have server/client distinction.
Yes! I actually have staged changes for that I forgot to push, thanks for the reminder! |
I remember what I got stuck on, with Playwright. I don't know how to trigger a network error as Axios identifies them. Maybe using |
/** | ||
* Record network errors using the appropriate tool, as needed, | ||
* based on response code, status, and request kind. | ||
* @param error - The error to record |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WebStorm is complaining that JSDoc does not describe the parameters correctly (error
instead of context
, originalError
and fetchingError
.
You can use Playwright's
I tried adding e2e error tests to this PR, and found that |
I was thinking about this as well. There are a few composables like this that might be better suited for plugins instead of composables. |
This PR doesn't work due to the analytics composable, so I'm going to close it for now, but leave the branch up. I'll open another PR to move analytics composable into a plugin. |
Fixes
Fixes #3468 by @krysal
Description
I've kept this PR as a draft because:
Testing Instructions
Force an error to happen in a network request on the frontend. For example, append a bogus string to the end of media IDs so that they result in 404s. Confirm that those don't get sent to Plausible or Sentry anymore (try it on
main
as well to see that it goes to Sentry).I don't know how to force a network error. You may be able to do it using your browser's network debugging tab and explicitly blocking a request.
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin