首页 > 解决方案 > 如何扩展 Fiori Standard App 的 ErrorHandler

问题描述

在下面的帖子中可能是我的问题的答案,但我没有看到:坚持使用通用 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 方法,要么找到一种方法来分离原始事件,然后我可以扩展或重写 ErrorHandler。我更喜欢后一种选择,因为我不仅要在这个标准 fiori 应用程序中扩展 ErrorHandler,而且还要在其他六个应用程序中扩展。而且总是重写 init-method 感觉比总是重写 ErrorHandler 更糟糕。

标签: javascriptsapui5sap-fiori

解决方案


我猜是因为您首先调用了初始化原始 ErrorHandler 的超级方法(即将事件处理程序附加到失败的请求等)。之后,您只需在自己的 ErrorHandler 中附加更多处理程序。您需要分离以前的处理程序(可能很棘手)或首先不初始化原始类。


推荐阅读