1

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?

3
  • The errors that you want to log from your Angular(client-end) are server related? or they are errors that related to web application it self ? Commented Jul 19, 2018 at 21:22
  • @dAxx_ Just the application itself. I'd use Angular's Error handler with RXJS I'm assuming, but I'm just wanting to be able to send it to the back end so that it can log it to the database for me, since I already have a database logger written. The more I think on it though, the more I feel I'll need to write a new logger anyway or include some if (client error) do this, if (server error) do this logic. Other than sending the error to my back end, I don't know of a way to directly send errors from Angular to a SQL Server table, which is where we are wanting to store these errors. Commented Jul 19, 2018 at 21:29
  • 2
    If you only want to log client side errors(I dont know for what purpose, but I assume for tracking or data science), You can just build a service which POST errors to your server, You can construct your object from the client to match your server. Commented Jul 19, 2018 at 21:34

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for responding. I wasn't the one who downvoted you - I just upvoted you so that brought you back up to '0' upvotes. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.