如何从oData响应中恢复错误消息[SAPUI5] [英] How to recover a error message from oData response [SAPUI5]

查看:205
本文介绍了如何从oData响应中恢复错误消息[SAPUI5]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个问题,我搜寻了很多解决方法,但目前找不到任何解决方案...

I had this issue and i searched a lot how to fix it, but i can't find any solution at the moment...

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

well, the issue is the next error message, i can write the error but i need a specific entry of this batch.

错误,消息框和批处理响应。

消息框中显示的代码:

{
message: HTTP请求失败,
headers:{
Content-Type: application / xml; charset = utf-8,
Content-Length: 1333,
DataServiceVersion: 1.0
},
statusCode : 400,
statusText:错误的请求,
responseText: http:// schemas .microsoft.com / ado / 2007/08 / dataservices / metadata\> SY / 530 无其他条件/SAP/ZQMGW_LECTURATANQUE_SRV00019488BBDEFA9E11E685950000705EE2FB20170224144147.5230000运行交易/ IWFND / ERRO在SAP Gateway集线器系统上进行R_LOG并搜索带有上述时间戳的条目以获取更多详细信息,请参阅SAP Note 1797736进行错误分析(https://服务。 sap .com / sap / support / notes / 1797736)有关使用$ batch的详细信息,请参阅SAP注释1869434(https:// service。sap。com / sap / support / notes / 1869434)不构成任何错误。 code> / IWBEP / CX_SD_GEN_DPC_BUSINS 没有造成任何人身伤害的错误
}

{ "message": "HTTP request failed", "headers": { "Content-Type": "application/xml;charset=utf-8", "Content-Length": "1333", "DataServiceVersion": "1.0" }, "statusCode": "400", "statusText": "Bad Request", "responseText": "http://schemas .microsoft.com/ado/2007/08/dataservices/metadata\">SY/530No posee permisos para el Centro seleccionado/SAP/ZQMGW_LECTURATANQUE_SRV00019488BBDEFA9E11E685950000705EE2FB20170224144147.5230000Run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more detailsSee SAP Note 1797736 for error analysis (https: //service. sap .com/sap/support/notes/1797736)See SAP Note 1869434 for details about working with $batch (https: //service. sap. com/sap/support/notes/1869434)No posee permisos para el Centro seleccionadoerror/IWBEP/CX_SD_GEN_DPC_BUSINSNo posee permisos para el Centro seleccionadoerror" }

我需要仅恢复消息标签,但我不知道如何......

i need to recover the message tag only, but i don't know how....

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

the code what i'm using is the native error handling for Sapui5 Fiori Apps:

    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)
            }
        );
    }

如果有人知道如何恢复该价值,我将非常感激。

if someone knows how to recover that value, I'll be very greatful.

问候。

推荐答案

i解决了此问题,更改了此部分代码的

i fixed this issue, changing this part of the code

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);

这篇关于如何从oData响应中恢复错误消息[SAPUI5]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆