I have come across this interceptor in my Angular project:
angular.module('dwExceptionHandler', [])
.factory('ExceptionInterceptor', ['$q', function ($q) {
return function (promise) {
return promise.then(
function (response) {
if (response && response.data.Exception) {
alert(response.data.Exception.Message);
return $q.reject(response);
}
return response;
},
function (response) {
if (response.data.Exception) {
console.warn('ALERT', response.data.Exception.Message);
alert(response.data.Exception.Message.replace(/\\n/g, '\n'));
}
return $q.reject(response);
});
};
}]).config(["$httpProvider", function ($httpProvider) {
$httpProvider.responseInterceptors.push('ExceptionInterceptor');
}]);
Despite expecting an alert due to receiving an exception from the server, the alert is not displayed. Strangely it does show up in the development environment without minification.
Upon inspecting the minified code snippet, I noticed it looks like this:
angular.module("dwExceptionHandler",[]).factory("ExceptionInterceptor",["$q",function(n)
{
return function(t){
return t.then(function(t)
{
return
t && t.data.Exception
? (alert(t.data.Exception.Message),n.reject(t))
: t
},
function(t)
{
return t.data.Exception
&&
( console.warn("ALERT",t.data.Exception.Message),
alert(t.data.Exception.Message.replace(/\\n/g,"\n"))),
n.reject(t)
})
}}])
.config(["$httpProvider",function(n){n.responseInterceptors.push("ExceptionInterceptor")}]);
It appears that both the promise
and response
variables are being assigned the same variable t
during minification.
I am seeking guidance on how to address this issue. Unfortunately, I am constrained by using the .NET Bundle configuration and cannot switch to grunt, gulp, or use web essentials as per restrictions. How can I resolve this situation?