Send Angular (6) client side errors to web API for logging

妖精的绣舞 提交于 2020-01-06 05:31:08

问题


Another person asked my exact question here with no answer: Angular 2 Client Side Errors

I'm wanting a way (avoiding additional third party frameworks if possible) to send my client-side Angular errors to my back end exception logger.

My back end is just a .NET Web API project that's connected to our SQL Server database. My server side errors are currently being logged to the database by calling a stored procedure controller whenever a server error occurs (I used KudVenKat's tutorial to build this: http://csharp-video-tutorials.blogspot.com/2012/12/logging-exception-to-database-part-75.html).

Is there a way to write an Angular service which calls my ErrorLogger API to log my Angular errors to the database?

I figure I may have to tweak my back end logger controller since it's using .NET's System.Exception class, which I'm guessing is only good for detecting server side exceptions, not Angular's. I may need an entirely different logger controller and database table for client side errors only - but I'd like server and client side errors logged to the same table if possible.

Knowing this - is what I'm trying to do even a good approach? If not, can anyone give me a high level description of how I might go about logging these client side errors instead?


回答1:


Angular provides global error handler service for handling the errors.

We can create our own custom error handler service which extends ErrorHandler .

In the handleError method you can call API and pass the client error to server

You can refer https://angular.io/api/core/ErrorHandler



来源:https://stackoverflow.com/questions/51431873/send-angular-6-client-side-errors-to-web-api-for-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!