cancel
Showing results for 
Search instead for 
Did you mean: 

submitChanges error callback not working in version 1.28.22 or am I doing error handling wrong ?

Attila
Active Participant
0 Kudos

Dear SCN Members,

I'm trying to submit the changes by the user and catch errors, before calling a function import doing the save in the ABAP OData service. The success callback is executed always, however the submit request fails, due an error raised by the GateWay itself, and not by my application code.

In my view controller, first I submit the changes, and it results in a successful calback of onSaveAfterSubmit


// Submitting pending changes

onSave: function() {

  this._oHelper.createBusyDialog();

  if (this._oModel.hasPendingChanges()) {

  this._oHelper.submitAllChangesCE(

  this.onSaveAfterSubmit.bind(this),

  this.onSaveSubmitFailed.bind(this)

  );

  }

},

onSaveSubmitFailed: function(oError){

  var oErrorInt = oError;

},

onSaveAfterSubmit: function(oData,oReponse) {

  this._oHelper.saveRequest(

  this._oView.getModel().getProperty(this._sItemPath).Id,

  jQuery.proxy(this._requestSaveSuccess, this)

  );

},

},

// Submitting pending changes to entities registered in deferred batch groups

submitAllChangesCE: function(fnSuccess, fnError) {

  this._oDataModel.submitChanges({

  success: fnSuccess,

  error: fnError

  });

},

this._oModel.attachRequestFailed(null, cust.ecc.md.vendor.requester.util.messages.showErrorMessage);

Instead of function onSaveSubmitFailed, always the cust.ecc.md.vendor.requester.util.messages.showErrorMessage is called, whenever the length of the user input is longer than the maximum length of the DDIC field behind. This exception is raised by the GW itself, and not by my application:


HTTP request failed400,

Bad Request,{"error":{"code":"/IWCOR/CX_DS_EDM_FACET_ERROR/005056A509B11ED1BDCCCC5E8168819D","message":{"lang":"en","value":"Value 'SOGEFRPP                      ' violates facet information 'maxlength=11'"}

What I do not understand, that why is onSaveAfterSubmit called at all, in the case the request fails, together with showErrorMessage.

I want to prevent the Save on a nice way in this case, because at the moment the success callback is exeuted doing the Save in the backend, however the changes could not be submitted, and get lost.

Any idea, how to do that nicely ?

Should I set a boolean in the cust.ecc.md.vendor.requester.util.messages.showErrorMessage ? This would be not really nice, at least in my opinion , there should be a better way or concept to manage this.

Thank you, Attila

Accepted Solutions (1)

Accepted Solutions (1)

jamie_cawley
Advisor
Advisor

You can look at the oResponse.statusCode to determine if the execution was successful.  The error function is when the connection request fails.

Regards,

Jamie

SAP - Technology RIG

Attila
Active Participant

Thanks  Jamie, nice closing of my working hours

Answers (0)