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

Issue with asset upload. #132

Closed
manirohit1002 opened this issue Aug 9, 2017 · 6 comments
Closed

Issue with asset upload. #132

manirohit1002 opened this issue Aug 9, 2017 · 6 comments

Comments

@manirohit1002
Copy link

Hi there,
Getting below error while uploading and processing an asset. Can you please look into it.
(node:54832) UnhandledPromiseRejectionWarning: Unhandled promise rejection (reje
ction id: 3): 400 Bad Request: {
"status": 400,
"statusText": "Bad Request",
"message": "",
"details": {},
"request": {
"url": "https://api.contentful.com:443/spaces/",
"headers": {
"Accept": "application/json, text/plain, /",
"Content-Type": "application/vnd.contentful.management.v1+json",
"X-Contentful-User-Agent": "sdk contentful-management.js/3.10.0; platform
Node.js/8.1.4; os Win32/0.0.0",
"Authorization": "Bearer ...ac599",
"user-agent": "node.js/v8.1.4",
"Accept-Encoding": "gzip",
"host": "api.contentful.com:443"
},
"method": "get"
}
We are behind corporate proxy but after deploying on heroku also getting the same error.
Thanks

@axe312ger
Copy link
Collaborator

Hey Rohit,

using proxies with our JS SDK can be a little bit tricky. The main reason is our dependency Axios which automatically tries to use the correct proxy settings. This turns out to be problematic for some users.

Option 1: Set your proxy config via the proxy configuration option

The proxy config is just passed to Axios, that's why you can use the same format as in the Axios documentation:

const client = ContentfulManagement.createClient({
  accessToken: <YOUR_ACCESS_TOKEN>,
  proxy: {
    host: '127.0.0.1',
    port: 9000,
    auth: {
      username: 'mikeymike',
      password: 'rapunz3l'
    }
  }
})

Option 2: the httpAgent option got split up into httpAgent and httpsAgent

Our dependency axios "quietly" split up their httpAgent into one for every protocol (http & https).

We catched this too late, this is why the change went into the SDK as minor/feature release instead as a major/breaking release. Sorry for this, usually we try to avoid breaking changes within major releases.

Option 3: Environment variables on your machine might cause issues

Axios automatically picks up environment variables and uses these as proxy configuration. It can help to remove these from node's process.env object before you run the SDK.

delete process.env['http_proxy']
delete process.env['HTTP_PROXY']
delete process.env['https_proxy']
delete process.env['HTTPS_PROXY']

There is a pull request open in the Axios repository adding a possibility to disable this behavior. axios/axios#691

On mid/long-term we try to eliminate the axios dependency completely, automatically resolving especially the last workaround.

Good luck, since proxies can be difficult to set up,
Benedikt

@manirohit1002
Copy link
Author

Hi @axe312ger,

Thanks for the information, we tried the option provided by you to setting up the proxy. but still getting the same error. :(

We are creating the proxy agent like below
exports.createProxyAgent = function () {
let proxyAgent;
if (process.env.NODE_ENV === 'development') {
const HttpsProxyAgent = require('https-proxy-agent');
const proxy = process.env.PROXY;
console.log('Using proxy server: %s', proxy);
proxyAgent = new HttpsProxyAgent(proxy);
}
return proxyAgent;
};

and calling in the create client function . below is the code

const cfClient = contentful.createClient({
// This is the space ID. A space is like a project folder in Contentful terms
space: process.env.CONTENTFUL_SPACEID,
accessToken: process.env.CONTENTFUL_ACCESSTOKEN,
agent: createProxyAgent(),
});

@Khaledgarbaya
Copy link
Contributor

Khaledgarbaya commented Aug 9, 2017

Hi @manirohit1002,
your creation of the client should be like this

const cfClient = contentful.createClient({
// This is the space ID. A space is like a project folder in Contentful terms
space: process.env.CONTENTFUL_SPACEID,
accessToken: process.env.CONTENTFUL_ACCESSTOKEN,
httpsAgent: createProxyAgent(),
});

note the httpsAgent

@manirohit1002
Copy link
Author

Hi @Khaledgarbaya ,

yeah, sorry I have corrected it. but now i am getting following error -

(node:8624) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: connect ECONNREFUSED 151.101.44.249:443
[warning] Connection error occured. Waiting for 2112 ms before retrying...
[warning] Connection error occured. Waiting for 2529 ms before retrying...
[warning] Connection error occured. Waiting for 3463 ms before retrying...
[warning] Connection error occured. Waiting for 4588 ms before retrying...
[warning] Connection error occured. Waiting for 6331 ms before retrying...
(node:8624) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 16): TypeError: self.agent.addRequest is not a function

@axe312ger
Copy link
Collaborator

Looks like your proxy is refusing the connections. Are you sure u are using the correct configuration?

Also, a full error stack trace might help us to help you :)

@Khaledgarbaya
Copy link
Contributor

I am closing this issue since it is inactive, feel free to open a new one

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

No branches or pull requests

3 participants