[英]How to extend ErrorHandler of Fiori Standard App
在下面的帖子中可能是我的问题的答案,但我没有看到它: 坚持使用通用 ErrorHandler.js 同时允许每个请求自定义错误消息处理并且没有双消息框
我正在扩展一个 Fiori 标准应用程序(具体来说是 MyProfile),所以一切正常。 现在,客户希望根据从网关发送的技术消息显示特殊的错误消息。 所以我尝试在Component.js 中扩展 ErrorHandler :
jQuery.sap.declare("com.company.hcm.fab.myprofile.ext.Component");
jQuery.sap.require("com.company.hcm.fab.myprofile.ext.controller.ErrorHandler");
sap.ui.component.load({
name: "hcm.fab.myprofile",
url: "/sap/bc/ui5_ui5/sap/hcmfab_prfl_mon"
});
this.hcm.fab.myprofile.Component.extend("com.company.hcm.fab.myprofile.ext.Component", {
metadata: {
manifest: "json"
},
init: function() {
hcm.fab.myprofile.Component.prototype.init.apply(this, arguments);
this._oErrorHandler = new com.company.hcm.fab.myprofile.ext.controller.ErrorHandler(this);
}
});
我按照我从显示的帖子中理解的方式扩展了ErrorHandler.js :
sap.ui.define([
"hcm/fab/myprofile/controller/ErrorHandler",
"sap/m/MessageBox"
], function(ErrorHandler, MessageBox) {
"use strict";
return ErrorHandler.extend("com.company.hcm.fab.myprofile.ext.controller.ErrorHandler", {
constructor: function (oComponent) {
this._oResourceBundle = oComponent.getModel("i18n").getResourceBundle();
this._oComponent = oComponent;
this._oModel = oComponent.getModel();
this._sErrorText = this._oResourceBundle.getText("errorTitle");
this._oModel.attachRequestFailed(this._requestFailedHandler, this);
},
_requestFailedHandler: function(oEvent) {
var oParameters = oEvent.getParameters();
console.log("now?", oResponse);
this._showServiceError(oParameters.response);
}
});
});
无论如何,我不仅会看到我的消息,而且还会在标准应用程序中看到来自 ErrorHandler 的消息。 有没有人有想法?
最好的问候马可
更新澄清我的想法:在我正在扩展的原始应用程序中,ErrorHandler 在 init-Method 中初始化。 因此,如果我做对了,我要么完全重写/覆盖 init-Method,要么找到一种方法来分离原始事件,然后我可以扩展或重写 ErrorHandler。 我更喜欢后面的选项,因为我不仅要在这个标准 fiori 应用程序中扩展 ErrorHandler,还要扩展其他六个应用程序。 而且总是重写 init 方法比总是重写 ErrorHandler 感觉更糟。
我猜是因为您首先调用了初始化原始 ErrorHandler 的 super 方法(即将事件处理程序附加到失败的请求等)。 之后,您只需在自己的 ErrorHandler 中附加更多处理程序。 您需要分离以前的处理程序(可能很棘手)或首先不初始化原始类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.