如何从oData响应[SAPUI5]

时间:2017-02-24 15:06:54

标签: error-handling sap sapui5 sap-fiori

我有这个问题,我搜索了很多如何解决它,但我现在找不到任何解决方案......

好吧,问题是下一条错误消息,我可以写错误,但我需要这个批次的特定条目。

Error, Messagebox and Batch response.

代码显示在消息框中:

{     " message":" HTTP请求失败",     "标题":{         " Content-Type":" application / xml; charset = utf-8",         "内容长度":" 1333",         " DataServiceVersion":" 1.0"     },     " statusCode":" 400",     " statusText":"错误请求",     " responseText":" http:// schemas .microsoft.com / ado / 2007/08 / dataservices / metadata \"> SY/530没有posee permisos para el Centro seleccionado / SAP / ZQMGW_LECTURATANQUE_SRV00019488BBDEFA9E11E685950000705EE2FB20170224144147.5230000Run交易/ IWFND / error_log中对SAP门户枢纽系统和上面更detailsS​​ee SAP注释1797736时间戳进行误差分析(HTTPS搜索条目://服务SAP的.com / SAP /支持/注意事项/ 1797736)有关使用$ batch(https:// service.sap.com / sap / support / notes / 1869434)的详细信息,请参阅SAP Note 1869434.No posee permisos para el Centro seleccionadoerror /IWBEP/CX_SD_GEN_DPC_BUSINS没有posee permisos para el Centro seleccionadoerror" }

我只需要恢复邮件标记,但我不知道如何......

我正在使用的代码是Sapui5 Fiori应用程序的本机错误处理:

    constructor: function(oComponent) {
        this._oResourceBundle = oComponent.getModel("i18n").getResourceBundle();
        this._oComponent = oComponent;
        this._oModel = oComponent.getModel();
        this._bMessageOpen = false;
        this._sErrorText = this._oResourceBundle.getText("errorText");

        this._oModel.attachMetadataFailed(function(oEvent) {
            var oParams = oEvent.getParameters();
            this._showServiceError(oParams.response);
        }, this);

        this._oModel.attachRequestFailed(function(oEvent) {
            var oParams = oEvent.getParameters("message");
            // An entity that was not found in the service is also throwing a 404 error in oData.
            // We already cover this case with a notFound target so we skip it here.
            // A request that cannot be sent to the server is a technical error that we have to handle though
            if (oParams.response.statusCode !== "404" || (oParams.response.statusCode === 404 && oParams.response.responseText.indexOf(
                    "Cannot POST") === 0)) {
                this._showServiceError(oParams.response);
            }
        }, this);
    },

    /**
     * Shows a {@link sap.m.MessageBox} when a service call has failed.
     * Only the first error message will be display.
     * @param {string} sDetails a technical error to be displayed on request
     * @private
     */
    _showServiceError: function(sDetails) {
        if (this._bMessageOpen) {
            return;
        }
        this._bMessageOpen = true;
        MessageBox.error(
            this._sErrorText, {
                id: "serviceErrorMessageBox",
                details: sDetails, 
                styleClass: this._oComponent.getContentDensityClass(),
                actions: [MessageBox.Action.CLOSE],
                onClose: function() {
                    this._bMessageOpen = false;
                }.bind(this)
            }
        );
    }

如果有人知道如何恢复这个价值,我会非常感激。

问候。

2 个答案:

答案 0 :(得分:4)

我解决了这个问题,改变了这部分代码

if (oParams.response.statusCode !== "404" || (oParams.response.statusCode === 404 && oParams.response.responseText.indexOf(
                "Cannot POST") === 0)) {
            this._showServiceError(oParams.response);
        }
    }, this);

if (oParams.response.statusCode !== "404" || (oParams.response.statusCode === 404 && oParams.response.responseText.indexOf(
                    "Cannot POST") === 0)) {
                this._showServiceError($(oParams.response.responseText).find("message").first().text());

            }
        }, this);

答案 1 :(得分:0)

检查您的SAP ABAP存储库中是否有HCM_LRQ_CRE BSP应用程序,实际上它是HCM请求Fiori应用程序。你可以在那里找到DataManager-dbg.js文件。查看 parseErrorMessages 方法,它可以很好地解析SAP消息。可能你可以用它作为起点。