Skip to Content
0
Nov 24, 2020 at 07:12 AM

Can't call external service when using the OData v2 proxy on CAP project

122 Views Last edit Nov 24, 2020 at 07:13 AM 3 rev

I have a CAP project which calls an external service to start a workflow.

When I add the odata v2 proxy so that I can use a fiori elements app for some reason the external service call fails.

The external service url is: https://api.workflow-sap.cfapps.ap10.hana.ondemand.com/workflow-service/rest/v1/workflow-instances

The errors I see are:

2020-11-24T14:51:03.84+0800 [APP/PROC/WEB/0] OUT {"message":"Successfully retrieved destination from destination service.","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor-service"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-11-24T06:51:03.847Z","msg":"Successfully retrieved destination from destination service.","written_ts":1606200663847,"written_at":"2020-11-24T06:51:03.847Z"}
   2020-11-24T14:51:03.84+0800 [APP/PROC/WEB/0] OUT {"message":"Try to fetch https_proxy or HTTPS_PROXY from the process env. Found value is undefined","level":"info","custom_fields":{"package":"core","messageContext":"proxy-util"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-11-24T06:51:03.847Z","msg":"Try to fetch https_proxy or HTTPS_PROXY from the process env. Found value is undefined","written_ts":1606200663847,"written_at":"2020-11-24T06:51:03.847Z"}
   2020-11-24T14:51:03.84+0800 [APP/PROC/WEB/0] OUT {"message":"No Proxy settings for https are found in environment variables - no proxy used","level":"info","custom_fields":{"package":"core","messageContext":"proxy-util"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-11-24T06:51:03.847Z","msg":"No Proxy settings for https are found in environment variables - no proxy used","written_ts":1606200663847,"written_at":"2020-11-24T06:51:03.847Z"}
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR [2020-11-24T06:51:04.014Z | ERROR | 1902147]: Error: Failed to build HTTP request for destination: failed to build headers!
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at Object.errorWithCause (/home/vcap/app/node_modules/@sap-cloud-sdk/util/dist/error.js:5:20)
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at /home/vcap/app/node_modules/@sap-cloud-sdk/core/dist/http-client/http-client.js:195:38
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at process._tickCallback (internal/process/next_tick.js:68:7)
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR Caused by:
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR Error: Request for "OAuth2ClientCredentials" authentication access token failed or denied.
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at Object.errorWithCause (/home/vcap/app/node_modules/@sap-cloud-sdk/util/dist/error.js:5:20)
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at /home/vcap/app/node_modules/@sap-cloud-sdk/core/dist/header-builder/authorization-header.js:166:38
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at process._tickCallback (internal/process/next_tick.js:68:7)
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR Caused by:
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR Error: FetchTokenError: Client credentials Grant failed! Request failed with status code 401

So even though the error says something about the authentication, I did not get this error and calling the external service worked fine before adding the odata v2 proxy. Any ideas? The initial error above is somthing to do with a proxy...

My v2 adapter proxy is as follows (straight from the doco on the npm registry):

"use strict";

const cds = require("@sap/cds");
const proxy = require("@sap/cds-odata-v2-adapter-proxy");

cds.on("bootstrap", app => app.use(proxy()));

module.exports = cds.server;