1
votes

I'm working with OData V2 Model with enabled batch-support.

When the backend process is running without throwing any exceptions, the Success-Callback is never called.

But when there's a backend exception, the Success-Callback is called (not error-callback, Bug?). Therefore I'm checking for the statuscode in the Success-Callback.

Is there another possibility to get the statuscode or a success-callback in general? Maybe with attachBatchRequestCompleted?

Binding to View:

this.setModel(this.getOwnerComponent().getModel());
this.getModel().metadataLoaded().then(function () {
    var sObjectPath = this.getModel().createKey(sEntity, { 
        UserId: sUserId
    });
    this.getView().bindElement({
        path: "/" + sObjectPath
    });
}.bind(this));

Submit-Call:

this.getView().getModel().submitChanges({ 
                                success: function (oData) {
                                    try {
                                        if (oData.__batchResponses[0].response.statusCode >= 400) {
                                            //Error
                                        }
                                    } catch (err) {
                                    },
                            error: function (oError) {
                            });
1

1 Answers

3
votes

This depends on the batch mode setting (see setBatchMode)

If batch mode is off, the success callbacks are not called at all (see submitChanges).

If batch mode is on, the success callback is called, if the batch is successful even if some of the actual requests within the batch fail.

The error callback is called, if the actual batch failed (almost never - except during development).

If requests are aborted, the handlers are called as follows (see submitChanges)

If there are no changes/requests or all contained requests are aborted before a batch request returns, the success handler will be called with an empty response object. If the abort method on the return object is called, all contained batch requests will be aborted and the error handler will be called for each of them.

PS: you can use sap.ui.core.message.MessageManager to display errors in a standardized way.