Sending client-side JS errors to the server for error reporting
You can get a similar effect of services like Sentry by catching global unhandled errors events and sending them to the back-end to implement a custom error reporting system, eg:
window.onunhandledrejection will handle events raised for unhandled Promise rejections. Before setting the event handler we need to check if it’s supported by the browser.
These handlers can be expanded to included further context and other events can be used as well to build a more comprehensive reporting system.