1
votes

I'm using BreezeJS with Angular to consume data from a Restful OData Service provided by an SAP Netweaver Gateway System. The application is currently reading the data from the service correctly, including the metadata and has this all held in the EntityManager as expected.

However when I change the status of one of the entities and perform a saveChanges(), neither the success nor failure callbacks are called, instead a console error is displayed.

Uncaught TypeError: Cannot read property 'statusText' of undefined 

The code calling the save is as follows

$scope.doSave = function(){
    $scope.purchases[0].Requester = "Dave" ;
        $scope.items[0].Description = "New Description";
        if (!$scope._isSaving)
        {
            console.log("Saving!");
            $scope._isSaving = true;
            manager.saveChanges().then(function(data){
                console.log("Saved");
                console.log(data);
                $scope._isSaving = false;
            }, function(error){
                console.log(error); 
                $scope._isSaving = false;});
        }
}

Where manager is a standard Breeze EntityManager.

The code is minified on a server and so is very hard to debug through, but this is being thrown within one of the core breeze libraries.

The client is performing a $batch POST request to the server, and the server is responding with a 202 Accepted, as below

--0DD0586DB234C0A3D0D530A25CD1C8400
Content-Type: multipart/mixed; boundary=0DD0586DB234C0A3D0D530A25CD1C8401
Content-Length:       519

--0DD0586DB234C0A3D0D530A25CD1C8401
Content-Type: application/http
Content-Length: 111
content-transfer-encoding: binary

HTTP/1.1 204 No Content
Content-Type: text/html
Content-Length: 0
dataserviceversion: 2.0
content-id: 1


--0DD0586DB234C0A3D0D530A25CD1C8401
Content-Type: application/http
Content-Length: 111
content-transfer-encoding: binary

HTTP/1.1 204 No Content
Content-Type: text/html
Content-Length: 0
dataserviceversion: 2.0
content-id: 2


--0DD0586DB234C0A3D0D530A25CD1C8401--

--0DD0586DB234C0A3D0D530A25CD1C8400--

I'm hoping this is something that somehere here has seen before!

1
Are you checking the value of statusText somewhere in your code?PW Kad
You should show how breeze manager gets entities, how you change themDidar_Uranov
Hi, thanks for the comments. Since I posted this I've managed to debug my way through it somewhat more and it appears that the problem is that the returned data has "Content-Type: text/html" along with the 204 No Content header. DataJS interprets this as having data, as it has a Content-Type thus causing it to try and read the data and then consequently fail, as it has no handler for type text/html, this propogates back to Breeze and instead of the response object it is expecting it insead recieves a string "No handler for this data", it tries to check the statusText of this and fails.user3581810
Not quite sure how to fix this though, as I can't change the server behaviour here.user3581810

1 Answers

3
votes

In the end this proves to be a quirk of SAP Netweaver Gateway handling the OData. It sends a header when it shouldn't, and sends the "Content-ID" header as content-id.

To fix these I ended up having to add lines to readBatch method in datajs1.1.1 from

if (response.statusCode >= 200 && response.statusCode <= 299) {
     partHandler(context.handlerContext).read(response,   context.handlerContext);
} else {
     // Keep track of failed responses and continue processing the batch.
     response = { message: "HTTP request failed", response: response };
}

to

if (response.statusCode >= 200 && response.statusCode <= 299) {
    if (response.statusCode != 204) 
        partHandler(context.handlerContext).read(response,   context.handlerContext);
} else {
     // Keep track of failed responses and continue processing the batch.
     response = { message: "HTTP request failed", response: response };
}

and change line 15176 of breeze.debug.js from

var contentId = cr.headers["Content-ID"];

to

var contentId = cr.headers["content-id"];

This resolved the problem and ensured that the response was correctly dealt with.