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

Cannot gracefully handle error #1533

Closed
ComputerCarl opened this issue May 11, 2018 · 4 comments
Closed

Cannot gracefully handle error #1533

ComputerCarl opened this issue May 11, 2018 · 4 comments

Comments

@ComputerCarl
Copy link

ComputerCarl commented May 11, 2018

Summary

When this page redirects, it crashes the application and no error is caught.

const axios = require('axios');
const debug = require('debug')('downloadToBuffer');

// certificate errors some axios gets
// https://stackoverflow.com/questions/31673587/error-unable-to-verify-the-first-certificate-in-nodejs
// https://github.com/axios/axios/issues/284
// https://github.com/axios/axios/issues/535

var rootCas = require('ssl-root-cas').create();
require('https').globalAgent.options.ca = rootCas;

const https = require('https');
const agent = new https.Agent({ rejectUnauthorized: false });

let url = 'https://ih1.redbubble.net/image.99400032.8054/flat';
axios.get(url, {
    responseType: 'arraybuffer',
    httpsAgent: agent
})
    .then(result => ({ buffer: result.data }))
    .catch(err => {
        debug({ err });
    });

produces this;

    _http_client.js:131
    throw new Error('Protocol "' + protocol + '" not supported. ' +
    ^

Error: Protocol "http:" not supported. Expected "https:"
    at new ClientRequest (_http_client.js:131:11)
    at Object.request (http.js:38:10)
    at RedirectableRequest._performRequest (...\node_modules\follow-redirects\index.js:128:24)
    at RedirectableRequest._processResponse (...\node_modules\follow-redirects\index.js:209:10)
    at ClientRequest.RedirectableRequest._onNativeResponse (...\node_modules\follow-redirects\index.js:38:10)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:551:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)
    at TLSSocket.socketOnData (_http_client.js:440:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at TLSSocket.Readable.push (_stream_readable.js:208:10)

Context

  • axios version: v0.18.0
  • Environment: node v8.9.4, firefox, windows 7
@yadue
Copy link

yadue commented May 20, 2018

Same error for me, cant catch that error, breaks node js server.

@Kelanor
Copy link

Kelanor commented Aug 8, 2018

Same here too. I can't catch this error. It just crashes node application

  • axios version: v0.18.0
  • Environment: node v8.11.3, debian 9

@PavelPolyakov
Copy link

@Faburu do you have https_proxy env variable set when executing this?

I have exactly the same error, but mine is about https_proxy. Here is the issue: #1885

@chinesedfan
Copy link
Collaborator

Closed in favor of #1885.

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants