BreezeJs,调用SaveChanges() - 未捕获类型错误:无法读取的未定义的属性'状态文本“属性、文本、状态、错误

2023-09-13 04:05:01 作者:劳资就是王。

我使用的是与角BreezeJS消耗从宁静的OData服务用的SAP NetWeaver网关系统提供的数据。该应用目前正在从服务读取正确的数据,包括元数据,并且这一切EntityManager的召开符合市场预期。

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.

然而,当我改变实体之一的状态,并执行一个调用SaveChanges(),无论是成功还是失败回调调用,而是被显示在控制台错误

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 

在code调用保存如下:

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

当经理是一个标准的微风的EntityManager。

Where manager is a standard Breeze EntityManager.

在code已经过压缩在服务器上,所以很难通过调试,但这为核心微风图书馆之一中抛出。

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.

客户机正在执行一个$批次POST请求给服务器,并且服务器与202接受响应,如下面

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

我希望这是一件somehere这里之前已经见过!

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

推荐答案

在最后,这被证明是的SAP NetWeaver网关的处理OData的一个怪癖。它发出了一个头,当它不应该,并且将内容ID头为内容id。

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.

要修复这些我最后不得不行datajs1.1.1从

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

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

和改变从

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

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

这解决了这个问题,并确保响应正确处理。

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