Hi,
I took over a project and came across this error (warning) message in the logs:
[Deprecated] - srv.emit()used to send synchronous 'UPDATE' request. Please change this to srv.send() instead.
So I found the corresponding call with is like:
const cds = require('@sap/cds') cds.env.features.fetch_csrf = true this.on('UPDATE', '*', async (req) => { const funcLocApi = await cds.connect.to('API_FUNCTIONALLOCATION') const tx = funcLocApi.transaction(req) try { const query = req.query // req.headers contains etag value with 'If-Match' header const functionalLocation = await tx.emit({ query, headers: req.headers }) return functionalLocation } catch (error) { throw error } })
Content of packages.json - "@sap/cds" : "^5.9.8"
So I thought I simply change this to use srv.send()
// req.headers contains etag value with 'If-Match' header const headers = req.headers const data = req.data const path = req.path const functionalLocation = await tx.send({ method: 'UPDATE', path, data, headers })
But then I ran into this error message despite set cds.env.features.fetch_csrf = true: CSRF token validation failed
Then I tried to upgrade to "@sap/cds" : "^6.0.4" with additional package "@sap-cloud-sdk/http-client" : "^2.0.6" which seems to be mandatory since CDS version 6.
Running the line of code tx.send({ method: 'UPDATE', path, data, headers }) caused a new error: Conditional headers cannot be specified for &METHOD& operations
So maybe the ETag handling isn't necessary anymore? Otherwise how should I pass the ETag header since it basically is mandatory for an UPDATE / PATCH operation?
For testing purposes I removed the header again with a totally different error message: The specified HTTP method is not allowed for the resource identified by the Data Service Request URI
I played around with method: 'PATCH' which resulted in the exact same error message: The specified HTTP method is not allowed for the resource identified by the Data Service Request URI
So, the question is: do I use srv.send() the wrong way or is there an error since I probably have to pass a custom header since the behavior of srv.send() in 5.9.8 is different than in 6.0.4
Regards,
Andreas