Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot convert undefined or null to object #115

Closed
kevinbalboni opened this issue Dec 27, 2024 · 4 comments
Closed

TypeError: Cannot convert undefined or null to object #115

kevinbalboni opened this issue Dec 27, 2024 · 4 comments
Assignees

Comments

@kevinbalboni
Copy link

Hello,
After migrating to the @cap-js-community/odata-v2-adapter package, we found a problem in the payload management of some calls.
If null properties are passed in the odata body, this error is generated, which did not happen with @sap/cds-odata-v2-adapter-proxy.

In the following repository, you can see the anomaly: https://github.com/conse-srl/test_CAP

Steps to reproduce the error:
Start the server with the “start” command in the package.json.
Use the “test.http” file to make the POST “{{catService}}/saveElements” call.

The library will fail:
[cov2ap] - Request: TypeError: Cannot convert undefined or null to object at /home/user/projects/test_CAP/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:2636:7 at Array.forEach (<anonymous>) at convertRequestData (/home/user/projects/test_CAP/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:2635:10) at convertRequestData (/home/user/projects/test_CAP/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:2628:14) at /home/user/projects/test_CAP/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:2652:13 at Array.forEach (<anonymous>) at /home/user/projects/test_CAP/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:2642:25 at Array.forEach (<anonymous>) at convertRequestData (/home/user/projects/test_CAP/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:2641:10) at convertRequestData (/home/user/projects/test_CAP/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:2628:14) [cov2ap] - Request: Request with Error { method: 'POST', url: '/cat/saveElements', target: 'http://localhost:4004' } [odata] - POST /cat/saveElements [cov2ap] - [HPM] POST /odata/v2/cat/saveElements -> http://localhost:4004/cat/saveElements [408] [cds] - BadRequestError: request aborted at IncomingMessage.onAborted (/home/user/projects/test_CAP/node_modules/raw-body/index.js:245:10) at IncomingMessage.emit (node:events:518:28) at IncomingMessage._destroy (node:_http_incoming:224:10) at _destroy (node:internal/streams/destroy:121:10) at IncomingMessage.destroy (node:internal/streams/destroy:83:5) at abortIncoming (node:_http_server:794:9) at socketOnClose (node:_http_server:788:3) at Socket.emit (node:events:530:35) at TCP.<anonymous> (node:net:337:12) at TCP.callbackTrampoline (node:internal/async_hooks:130:17) { code: 'ECONNABORTED', expected: 619, length: 619, received: 0, type: 'request.aborted', statusCode: 400 } [error] - 400 > { message: 'request aborted', code: 'ECONNABORTED' }

Regards,
Kevin

@oklemenz2 oklemenz2 self-assigned this Dec 29, 2024
@oklemenz2
Copy link
Contributor

Thanks for reporting the issue and for the details to reproduce the error, I will have a look asap.

@oklemenz2
Copy link
Contributor

I made the request data processing more stable with 16ab786.

I will provide a new release start of next week.

In general:

The way you are calling OData V2 action with POST is not 100% conforming to OData V2 standard.
In contrast to OData V4, OData V2 does not natively support actions with POST body.
In OData V2 actions are also mapped to function imports. Function imports are called in OData V2 passing action body as URL parameters, like this: https://services.odata.org/OData/OData.svc/ProductsByColor?color='red'

Addressing Service Operations
https://www.odata.org/documentation/odata-version-2-0/uri-conventions/

This of course limits the action parameters to simple data types, without nesting structures.

That's why I also allow non-conformant action POST bodies like in OData V4, because I find the usage way more natural ;-)

@kevinbalboni
Copy link
Author

Thank you very much for the update!
I'm excited about the upcoming release at the beginning of next week, as it will allow me to continue my project.

@oklemenz2
Copy link
Contributor

1.14.0 is released: https://github.com/cap-js-community/odata-v2-adapter/releases/tag/v1.14.0
Please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants