0

The UI should have a global error handler that shows a popup message whenever an error is received through the API. I'm trying but I'm not getting, I did not find any example too. This should be done Marionette.js. Please help

I got a json file:

{
"errorcodes": [{
"message": "Invalid Email/Password Combination",
"reason": "com.catt.exceptions.catttCustomerPreferencesException: Invalid Email/Password Combination\r\n\tat com.catt.v1.controller.CustomersController.customerLogin(CustomersController.java:303)\r\n\tat sun.reflect.GeneratedMethodAccessor1008.invoke(Unknown Source)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:606)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerM...",
"type": "tCustomerPreferencesError"
}]
}
4

1 回答 1

1

您可以使用$.ajaxError来侦听 $.ajax 中发生的任何错误。

从那里,您可以制作一个木偶应用程序(例如),处理错误并显示警报

var App = new Marionette.Application();

App.vent.on('error', function(event, jqxhr){
    alert(jqxhr.responseText); 
});

$(document).ajaxError(function(event, jqxhr, settings, thrownError){
    App.vent.trigger('error', event, jqxhr, settings, thrownError);    
});

小提琴在这里:http: //jsfiddle.net/8ff4n9ut/

于 2015-02-03T03:34:44.567 回答