简体   繁体   中英

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

I am extending a Fiori Standard App (MyProfile to be concrete) and so everything works fine. 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 :

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:

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. 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. 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. 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. And always rewriting the init-method feels worse than always rewriting the ErrorHandler.

I guess because you first call the super method which initializes the original ErrorHandler (ie attaches event handlers to failed requests etc). Afterwards you just attach more handlers in your own ErrorHandler. You need to detach the previous handlers (might be tricky) or not initialize the original class in the first place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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