gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:46:35 24 4
gpt4 key购买 nike

我遇到了这个问题,我搜索了很多如何解决它,但我目前找不到任何解决方案......
好吧,问题是下一条错误消息,我可以写错误,但我需要这批的特定条目。
Error, Messagebox and Batch response.
消息框上显示的代码:

{"message": "HTTP request failed","headers": {"Content-Type": "application/xml;charset=utf-8","Content-Length": "1333","DataServiceVersion": "1.0"},"statusCode": "400","statusText": "Bad Request","responseText": "<?xml version=\"1.0\" encoding=\"utf-8\"?><error xmlns=\"http://schemas .microsoft.com/ado/2007/08/dataservices/metadata\"><code>SY/530</code><message xml:lang=\"es\">No posee permisos para el Centro seleccionado</message><innererror><application><component_id/><service_namespace>/SAP/</service_namespace><service_id>ZQMGW_LECTURATANQUE_SRV</service_id><service_version>0001</service_version></application><transactionid>9488BBDEFA9E11E685950000705EE2FB</transactionid><timestamp>20170224144147.5230000</timestamp><Error_Resolution><SAP_Transaction>Run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details</SAP_Transaction><SAP_Note>See SAP Note 1797736 for error analysis (https: //service. sap .com/sap/support/notes/1797736)</SAP_Note><Batch_SAP_Note>See SAP Note 1869434 for details about working with $batch (https: //service. sap. com/sap/support/notes/1869434)</Batch_SAP_Note></Error_Resolution><errordetails><errordetail><code/><message>No posee permisos para el Centro seleccionado</message><propertyref/><severity>error</severity><target/></errordetail><errordetail><code>/IWBEP/CX_SD_GEN_DPC_BUSINS</code><message>No posee permisos para el Centro seleccionado</message><propertyref/><severity>error</severity><target/></errordetail></errordetails></innererror></error>"}


我只需要恢复消息标签,但我不知道如何....
我正在使用的代码是 Sapui5 Fiori Apps 的 native 错误处理:
    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)
}
);
}
如果有人知道如何恢复该值(value),我将非常感激。
问候。

最佳答案

我修复了这个问题,更改了这部分代码

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

关于error-handling - 如何从 oData 响应中恢复错误消息 [SAPUI5],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42441931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com