问题
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.
Error, Messagebox and Batch response.
the code showed on the message box:
{
"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/530
No 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_BUSINS
No posee permisos para el Centro seleccionadoerror"
}
i need to recover the message tag only, but i don't know how....
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.
Greetings.
回答1:
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);
to
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);
回答2:
Check if you have HCM_LRQ_CRE BSP application in your SAP ABAP Repository, actually it is an HCM Leave Request Fiori app. You can find there DataManager-dbg.js file. Look into parseErrorMessages method, it parses SAP messages nicely. Probably you can use it as a starting point.
来源:https://stackoverflow.com/questions/42441931/how-to-recover-a-error-message-from-odata-response-sapui5