breeze allows to set error handler on application startup:
var ajaxAdapter = breeze.config.getAdapterInstance("ajax");
ajaxAdapter.requestInterceptor = function (requestInfo) {
// this method is called for every request made with breeze ajax adapter
// all callbacks are in zConfig
var
successHandler = requestInfo.zConfig.success,
errorHandler = requestInfo.zConfig.error || handleBadRequest,
finalHandler = requestInfo.zConfig.finally; // final handler for calls, made directly with adapter
if (finalHandler) {
requestInfo.zConfig.success = function (response) {
if(successHandler) {
successHandler(response);
}
finalHandler(response);
}
}
requestInfo.zConfig.error = function (response) {
switch (response.status) {
case 400:
// call error handler only for 'BadRequest'
errorHandler(parseErrors(response));
break;
case 401:
handleUnauthorizedRequest(response);
break;
default:
handleServerOrUnrecognizedError(response);
break;
}
if (finalHandler) {
finalHandler(response);
}
};
};