Skip to content

Fix handled Axios errors showing as unhandled

Erwan Rouchet requested to merge fix-unhandled-handled-errors into master

Closes #416 (closed), #426 (closed), #427 (closed), #428 (closed), #447 (closed), #543 (closed), #544 (closed), and resolves this thread

When making an API call using the helpers in js/api.js that use the unique() decorator, any error thrown by Axios would cause an "uncaught error in promise" error in the JavaScript console. This only occurred in web browsers and not in a Node.js context, so not in unit tests.

I found this randomly by troubleshooting an HTTP error that was well handled in !1262 (merged) but was still marked as uncaught: after a while, I found out that removing unique() from the API helper removed the error log. I experimented around and found that using Promise.finally() caused this log to show up.

It's been a very long time since we had this kind of issue and I never found any real documentation on how Promise and async interact with each other, especially with error handling, so I have no real idea why this seems to occur. However, I found that rewriting the .finally() to use a try {} finally {} construct inside of an async function did not cause the uncaught error warnings.

I went through most of the frontend issues that were marked as Axios errors. Some issues still remain because they are about errors being sent to Sentry, and some errors are still sent to Sentry despite being properly handled, but in most cases, there are no more Uncaught Error (in promise) errors in the browser's console!

Merge request reports

Loading