[英]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.