I am trying to log my client-sided error on on the server side in my angular app. To do this, I am using stacktrace.js and I am using the following factory:
myApp.factory(
"exceptionLoggingService",
["$log","$window", "traceService",
function($log, $window, traceService){
function error(exception, cause){
$log.error.apply($log, arguments);
try{
var errorMessage = exception.toString();
var stackTrace = traceService.print({e: exception});
$.ajax({
type: "POST",
url: "/logger",
contentType: "application/json",
data: angular.toJson({
url: $window.location.href,
message: errorMessage,
type: "exception",
stackTrace: stackTrace,
cause: ( cause || "")
})
});
} catch (loggingError){
$log.warn("Error server-side logging failed");
$log.log(loggingError);
}
}
return(error);
}]
);
My problem here, is that I am not using jQuery in my app and I'd like to avoid it as much as possible. as a result when running this code, I get the expected error:
ReferenceError: $ is not defined
How can I make an ajax request without using the $http service here (to avoir circular references in the case)?