holidayextras / jsonapi-client

Easily consume a json:api service in Javascript.
MIT License
68 stars 19 forks source link

I got fatal error when sync resource #51

Open soap opened 7 years ago

soap commented 7 years ago

I got this error when try to sync resource. Any suggestion? I have defined simple resource with limited attributes.


λ ENV DEBUG=* node client.js
  superagent GET http://localhost:16006/rest/customers/226 +0ms
  superagent GET http://localhost:16006/rest/customers/226 -> 200 +115ms
  superagent end GET http://localhost:16006/rest/customers/226 +0ms
Get customer with id 226 { id: '226',
  type: 'customers',
  name: 'วริฏฐา อนุมณี',
  surname: '',
  status: 0 }
Try to update status to 1
TypeError: Cannot convert undefined or null to object
    at Resource._getDelta (D:\node.js\xcommerce\xorders-jsonapi-server\node_modules\jsonapi-client\lib\Resource.js:59:10)
    at Transport.update (D:\node.js\xcommerce\xorders-jsonapi-server\node_modules\jsonapi-client\lib\Transport.js:128:20)
    at Client._update (D:\node.js\xcommerce\xorders-jsonapi-server\node_modules\jsonapi-client\lib\Client.js:114:19)
    at .<anonymous> (D:\node.js\xcommerce\xorders-jsonapi-server\node_modules\jsonapi-client\lib\Resource.js:300:10)
    at eval (eval at denodeifyWithoutCount (D:\node.js\xcommerce\xorders-jsonapi-server\node_modules\promise\lib\node-extensions.js:90:10), <anonymous>:3:375)
    at tryCallTwo (D:\node.js\xcommerce\xorders-jsonapi-server\node_modules\promise\lib\core.js:45:5)
    at doResolve (D:\node.js\xcommerce\xorders-jsonapi-server\node_modules\promise\lib\core.js:200:13)
    at new Promise (D:\node.js\xcommerce\xorders-jsonapi-server\node_modules\promise\lib\core.js:66:3)
    at eval (eval at denodeifyWithoutCount (D:\node.js\xcommerce\xorders-jsonapi-server\node_modules\promise\lib\node-extensions.js:90:10), <anonymous>:3:229)
    at D:\node.js\xcommerce\xorders-jsonapi-server\client.js:20:22               
```                                                                       `
soap commented 7 years ago

It is about relationships in _getDelta() is undefined if I change to

if (typeof relationships != 'undefined') {
      Object.keys(relationships).forEach(function (i) {
          if (getMeta(relationships[i]).relation === "foreign") return;
          primaryRelations[i] = relationships[i];
      });
  }

It works fine.