Error handling 如何从oData响应[SAPUI5]中恢复错误消息

Error handling 如何从oData响应[SAPUI5]中恢复错误消息,error-handling,sapui5,sap-fiori,Error Handling,Sapui5,Sap Fiori,我有这个问题,我找了很多方法来解决它,但我现在找不到任何解决方案 好的,问题是下一个错误消息,我可以写错误,但我需要这个批的特定条目 消息框上显示的代码: { “消息”:“HTTP请求失败”, “标题”:{ “内容类型”:“应用程序/xml;字符集=utf-8”, “内容长度”:“1333”, “DataServiceVersion”:“1.0” }, “状态代码”:“400”, “状态文本”:“错误请求”, “responseText:“SY/530No posee permisos par

我有这个问题,我找了很多方法来解决它,但我现在找不到任何解决方案

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

消息框上显示的代码:

{ “消息”:“HTTP请求失败”, “标题”:{ “内容类型”:“应用程序/xml;字符集=utf-8”, “内容长度”:“1333”, “DataServiceVersion”:“1.0” }, “状态代码”:“400”, “状态文本”:“错误请求”, “responseText:“
SY/530
No posee permisos para el Centro seleccionado/SAP/ZQMGW_teachatanque_SRV00019488BBDEFA9E11E685950000705EE2FB20170224144147.5230000在SAP网关集线器系统上运行事务/IWFND/ERROR_日志,并搜索带有上述时间戳的条目以获取更多详细信息请参阅SAP备注1797736进行错误分析(https://service.sap.com/sap/support/notes/1797736)有关使用$batch的详细信息,请参见sap Note 1869434(https://service.sap.com/sap/support/notes/1869434)No posee permisos para el Centro selectionadError
/IWBEP/CX_SD_GEN_DPC_BUSINS
No posee permisos para el Centro selectionadError
” }

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

我使用的代码是针对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)
            }
        );
    }
如果有人知道如何恢复价值,我将非常感激


您好。

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

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

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

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


我检查了,但应用程序不在吗?有办法从控制台恢复文本?我可以打印一个值,例如,如果我将代码更改为this.\u sErrorText为this.\u sErrorText.responseText我可以打印整个响应,但我需要该响应的消息标记。完整的错误消息(粗体字符)为JSON格式:
{“message”:“HTTP请求失败”,…seleccionadoerror”}
如果将其复制并粘贴到例如jsonlint.com中,您可以验证它并更清楚地查看结构。在您的编码中,您已经检查了
oParams.response.statusCode。
如果执行此操作,会发生什么。
\u showServiceError(oParams.response.message)
?这就是您要找的吗?我以前试过,唯一的消息是“HTTP请求失败”"顺便说一句,我前几天发布的代码行解决了这个问题……如果你知道一个更优雅的解决方案,你能帮我吗?我检查了,但应用程序不在那里,有一种从控制台恢复文本的方法吗?我可以打印一个值,例如,如果我将代码更改为this.\u sErrorText.responseText我可以打印整个文本响应,但我需要该响应中的消息标记。粗体字符的完整错误消息是JSON格式的:
{“message”:“HTTP请求失败”,…SELECCIONADEORROR}
如果您将其复制并粘贴到例如jsonlint.com中,您可以验证它并更清楚地查看结构。在您的编码中,您已经检查了
oParams.response.statusCode。
如果您这样做会发生什么。
\u showServiceError(oParams.response.message)
?这就是您要找的吗?我以前试过,我得到的唯一消息是“HTTP请求失败”。顺便说一句,我用前几天发布的代码行解决了这个问题……如果您知道更优雅的解决方案,您能帮我吗?