简体   繁体   English

如何扩展Fiori Standard App的ErrorHandler

[英]How to extend ErrorHandler of Fiori Standard App

in the following post is probably the answer to my question, but I don't see it: Stick with generic ErrorHandler.js while allowing custom errormessage handling per request and not have double message boxes在下面的帖子中可能是我的问题的答案,但我没有看到它: 坚持使用通用 ErrorHandler.js 同时允许每个请求自定义错误消息处理并且没有双消息框

I am extending a Fiori Standard App (MyProfile to be concrete) and so everything works fine.我正在扩展一个 Fiori 标准应用程序(具体来说是 MyProfile),所以一切正常。 Now the customer wants to show special error messages depending on the technical message sent from the Gateway.现在,客户希望根据从网关发送的技术消息显示特殊的错误消息。 So I tried to extend the ErrorHandler in the Component.js :所以我尝试在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);
    }
});

And I extended the ErrorHandler.js in the way that I understood from the shown post:我按照我从显示的帖子中理解的方式扩展了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);
        }

    });

});

Never the less I don't only see my message, but also still see the message from the ErrorHandler in the standard app.无论如何,我不仅会看到我的消息,而且还会在标准应用程序中看到来自 ErrorHandler 的消息。 Does anyone have an idea?有没有人有想法?

Best regards Marco最好的问候马可

Update To clarify my ideas: In the original app, which I'm extending, the ErrorHandler is initialized in the init-Method.更新澄清我的想法:在我正在扩展的原始应用程序中,ErrorHandler 在 init-Method 中初始化。 So if I get it right, I have to either completely rewrite/overwrite the init-Method, or I find a way to detach the original Events and then I can extend or rewrite the ErrorHandler.因此,如果我做对了,我要么完全重写/覆盖 init-Method,要么找到一种方法来分离原始事件,然后我可以扩展或重写 ErrorHandler。 I prefer the later option, because I not only have to extend the ErrorHandler in this standard fiori app, but in six others as well.我更喜欢后面的选项,因为我不仅要在这个标准 fiori 应用程序中扩展 ErrorHandler,还要扩展其他六个应用程序。 And always rewriting the init-method feels worse than always rewriting the ErrorHandler.而且总是重写 init 方法比总是重写 ErrorHandler 感觉更糟。

I guess because you first call the super method which initializes the original ErrorHandler (ie attaches event handlers to failed requests etc).我猜是因为您首先调用了初始化原始 ErrorHandler 的 super 方法(即将事件处理程序附加到失败的请求等)。 Afterwards you just attach more handlers in your own ErrorHandler.之后,您只需在自己的 ErrorHandler 中附加更多处理程序。 You need to detach the previous handlers (might be tricky) or not initialize the original class in the first place.您需要分离以前的处理程序(可能很棘手)或首先不初始化原始类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM