最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript: 'Self signed certificate' error during API call - Stack Overflow

programmeradmin2浏览0评论

I'm automating some API calls in Javascript and a few days ago this error started appearing out of nowhere.

base.js:383
  1) Test API call
base.js:266
       Fourth test:
     FetchError: request to :443/mobile/v2/subscribers failed, reason: self signed certificate in certificate chain
      at ClientRequest.<anonymous> (node_modules/node-fetch/lib/index.js:1393:11)
      at TLSSocket.socketErrorListener (_http_client.js:387:9)
      at emitErrorNT (internal/streams/destroy.js:64:8)
      at _combinedTickCallback (internal/process/next_tick.js:138:11)
      at process._tickCallback (internal/process/next_tick.js:180:9)

I have spent countless hours trying to find a solution but nothing works. I've re-cloned the entire repo and everything. Does anybody know how to solve this?

What I did before this started happening:

  1. Installed npm config
  2. Installed mongodb client

I've uninstalled since

I'm automating some API calls in Javascript and a few days ago this error started appearing out of nowhere.

base.js:383
  1) Test API call
base.js:266
       Fourth test:
     FetchError: request to https://api.qa.xx.xxxx.com:443/mobile/v2/subscribers failed, reason: self signed certificate in certificate chain
      at ClientRequest.<anonymous> (node_modules/node-fetch/lib/index.js:1393:11)
      at TLSSocket.socketErrorListener (_http_client.js:387:9)
      at emitErrorNT (internal/streams/destroy.js:64:8)
      at _combinedTickCallback (internal/process/next_tick.js:138:11)
      at process._tickCallback (internal/process/next_tick.js:180:9)

I have spent countless hours trying to find a solution but nothing works. I've re-cloned the entire repo and everything. Does anybody know how to solve this?

What I did before this started happening:

  1. Installed npm config
  2. Installed mongodb client

I've uninstalled since

Share Improve this question asked Jun 20, 2018 at 23:43 Python guyPython guy 1192 gold badges3 silver badges9 bronze badges 1
  • Not a lot here to look at really, but as default if you connect in node using a self signed certificate, it will error unless you turn of the check. Maybe this will help -> stackoverflow.com/questions/10888610/… – Keith Commented Jun 21, 2018 at 0:58
Add a comment  | 

1 Answer 1

Reset to default 20

Apparently there is a related issue with two solutions,

pass an http agent, setting rejectUnauthorized

const https = require("https");
const agent = new https.Agent({
  rejectUnauthorized: false
})
fetch(myUrl, { agent })

set an env var in your package.json start script

NODE_TLS_REJECT_UNAUTHORIZED="0" npm start

or use a process.env var

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
发布评论

评论列表(0)

  1. 暂无评论