0

I am trying to implement error logging, by following this tutorial: http://engineering.talis.com/articles/client-side-error-logging/

Errors are logged fine, but i have problems when i want to send the log to the server. I cant make http request. I tried:

   $.ajax({type: "POST"...})

But is says that $ is not defined. Also i tried to inject $http here:

loggingModule.factory( "exceptionLoggingService", ["$log","$window", "traceService","$http"...

But then i receive this error. Any ideas how to do this?

1 Answer 1

2

$.ajax() is a jQuery function. You're using AngularJS. So that's not surprising.

You have a circular dependency. This means that your exceptionLoggingService depends on $http, and $http depends (transitively) on exceptionLoggingService. To solve this error, you can lookup the $http service dynamically instead of having it injected:

loggingModule.factory('exceptionLoggingService', ['$injector', ..., function($injector, ...) {

    var sendErrorToServer = function(error) {
        $http = $injector.get('$http');
        $http.post(...);
    }
}

Note that there is still a circular dependency, which can cause problems is the logger is called when $http fails: that would call the logger to use $http, which would fail, which would cause the logger to be called, etc. etc.

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

1 Comment

even though question is irrelevant, i was able to learn issues related circular dependencies with this answer.. Thanks..

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.