abp.ng.min.js 2.9 KB

1
  1. (function(n,t){if(t){n.ng=n.ng||{};n.ng.http={defaultError:{message:"An error has occurred!",details:"Error detail not sent by server."},defaultError401:{message:"You are not authenticated!",details:"You should be authenticated (sign in) in order to perform this operation."},defaultError403:{message:"You are not authorized!",details:"You are not allowed to perform this operation."},defaultError404:{message:"Resource not found!",details:"The resource requested could not be found on the server."},logError:function(t){n.log.error(t)},showError:function(t){return t.details?n.message.error(t.details,t.message||n.ng.http.defaultError.message):n.message.error(t.message||n.ng.http.defaultError.message)},handleTargetUrl:function(t){location.href=t?t:n.appPath},handleNonAbpErrorResponse:function(t,i){if(t.config.abpHandleError!==!1)switch(t.status){case 401:n.ng.http.handleUnAuthorizedRequest(n.ng.http.showError(n.ng.http.defaultError401),n.appPath);break;case 403:n.ng.http.showError(n.ajax.defaultError403);break;case 404:n.ng.http.showError(n.ajax.defaultError404);break;default:n.ng.http.showError(n.ng.http.defaultError)}i.reject(t)},handleUnAuthorizedRequest:function(t,i){t?t.done(function(){n.ng.http.handleTargetUrl(i||n.appPath)}):n.ng.http.handleTargetUrl(i||n.appPath)},handleResponse:function(t,i){var r=t.data,u;r.success===!0?(t.data=r.result,i.resolve(t),r.targetUrl&&n.ng.http.handleTargetUrl(r.targetUrl)):r.success===!1?(u=null,r.error?t.config.abpHandleError!==!1&&(u=n.ng.http.showError(r.error)):r.error=defaultError,n.ng.http.logError(r.error),t.data=r.error,i.reject(t),t.status==401&&t.config.abpHandleError!==!1&&n.ng.http.handleUnAuthorizedRequest(u,r.targetUrl)):i.resolve(t)}};var i=t.module("abp",[]);i.config(["$httpProvider",function(t){t.interceptors.push(["$q",function(t){return{request:function(t){return t.url.indexOf(".cshtml")!==-1&&(t.url=n.appPath+"AbpAppView/Load?viewUrl="+t.url+"&_t="+n.pageLoadTime.getTime()),t},response:function(i){if(!i.data||!i.data.__abp)return i;var r=t.defer();return n.ng.http.handleResponse(i,r),r.promise},responseError:function(i){var r=t.defer();return i.data&&i.data.__abp?n.ng.http.handleResponse(i,r):n.ng.http.handleNonAbpErrorResponse(i,r),r.promise}}}])}]);n.event.on("abp.dynamicScriptsInitialized",function(){n.ng.http.defaultError.message=n.localization.abpWeb("DefaultError");n.ng.http.defaultError.details=n.localization.abpWeb("DefaultErrorDetail");n.ng.http.defaultError401.message=n.localization.abpWeb("DefaultError401");n.ng.http.defaultError401.details=n.localization.abpWeb("DefaultErrorDetail401");n.ng.http.defaultError403.message=n.localization.abpWeb("DefaultError403");n.ng.http.defaultError403.details=n.localization.abpWeb("DefaultErrorDetail403");n.ng.http.defaultError404.message=n.localization.abpWeb("DefaultError404");n.ng.http.defaultError404.details=n.localization.abpWeb("DefaultErrorDetail404")})}})(abp||(abp={}),angular||undefined);