SAP / cloud-sdk-js

Use the SAP Cloud SDK for JavaScript / TypeScript to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
164 stars 56 forks source link

ERR_BAD_REQUEST calling on-premise destination after CAP App is Deployed. #4640

Closed rodpf closed 6 months ago

rodpf commented 6 months ago

Hi Guys,

Everything works fine in BAS using proxy, application can READ the required information from S/4 On-Premise OData service without further issues, but after deploying the application it shows the error below:

"Error during request to remote service: \nRequest failed with status code 401","name":"AxiosError","stack":"AxiosError: Request failed with status code 401\n

{"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"method":"get","baseURL":"","url":"/sap/opu/odata/sap//?$select=Status&$top=1"},"code":"ERR_BAD_REQUEST","status":401},"id":"1141480","layer":"cds","component_type":"application","container_id":"","component_id":"","component_name":"-srv","...}

The destination is the same, both destination and connectivity services are bound with the application, I am using another on-premise SMTP destination (also via the same CC) and it is working fine.

This is how I am calling the backend:

`this.on('READ', 'ZENTITYSet', async (req) => {

            const s4API = await cds.connect.to('backend_destination')
            console.log('getting data from API Hub S/4HANA Sandbox System ')
            const query = req.query
            return  await s4API.send({ query, headers })
        });`

In despite I am using cds.conenct directly, I undertand that it uses @sap-cloud-sdk/http-client to connect

This is the definition of the destination in package.json

"'backend_destination": { "kind": "odata-v2", "model": "srv/external/'backend_destination", "credentials": { "destination": "'backend_destination", "path": "/sap/opu/odata/sap/<Servicename>" }, -->tried with and without parameters below "external":true, "impl":"@sap/cds/libx/_runtime/remote/Service.js" } What surprises me is the error, BAD_REQUEST and the same is not happening when running the project inside BAS, only when deploying the CAP application to BTP CF.

Can you please advise? This is a productive project, SIT should start next week and there will be 5 consultants stopped if that cannot be fixed.

Thanks and regards

mr-flannery commented 6 months ago

Hi @rodpf ,

can you please post the complete logs surrounding this request, the definition of your destination and what version of CAP and the SDK you're using?

mr-flannery commented 6 months ago

Problem was using the port 443 (maybe in connection with plain HTTP?) in the destination's URL.