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

2019-08-26 04:22发布

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条回答
手持菜刀,她持情操
2楼-- · 2019-08-26 04:30

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

查看更多
登录 后发表回答