Giter VIP home page Giter VIP logo

Comments (4)

ronag avatar ronag commented on July 20, 2024

Throw on error is not related to this.

throwOnError boolean (optional) - Default: false - Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server.

Here is a correct version of your code that does not throw uncaught:

request('http://www.rolbox.it/rk-kastelruth/webcam/web03.jpg', { throwOnError: false })
    .then(({ body }) => body.on('error', () => console.error("body error, err")))
    .catch(e => console.error('catch called:', e))
    .finally(() => console.log('finally called'));

from undici.

sandratatarevicova avatar sandratatarevicova commented on July 20, 2024

throwOnError boolean (optional) - Default: false - Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server.

Based on this, I would expect an error to be thrown as the request ends with 404.

from undici.

sandratatarevicova avatar sandratatarevicova commented on July 20, 2024

The stream function has the same behavior:

const fs = require('node:fs');
const { stream } = require('undici');

stream(
    'http://www.rolbox.it/rk-kastelruth/webcam/web03.jpg',
    {
        throwOnError: true,
        method: 'GET',
    },
    () => fs.createWriteStream('/tmp/test.jpg'),
)
    .then(() => console.log('then called'))
    .catch(e => console.error('catch called:', e))
    .finally(() => console.log('finally called'));

output:

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

HTTPParserError: Response does not match the HTTP/1.1 protocol (Invalid character in chunk size)
    at Parser.execute (/private/tmp/undici-test/node_modules/undici/lib/dispatcher/client-h1.js:277:15)
    at Parser.readMore (/private/tmp/undici-test/node_modules/undici/lib/dispatcher/client-h1.js:218:12)
    at Socket.<anonymous> (/private/tmp/undici-test/node_modules/undici/lib/dispatcher/client-h1.js:669:14)
    at Socket.emit (node:events:518:28)
    at emitReadable_ (node:internal/streams/readable:832:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:81:21) {
  code: 'HPE_INVALID_CHUNK_SIZE',
  data: ' \r\n' +
    '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n' +
    '<HTML><HEAD>\n' +
    '<TITLE>404 Not Found</TITLE>\n' +
    '</HEAD><BODY>\n' +
    '<H1>Not Found</H1>\n' +
    'The requested URL /rk-kastelruth/webcam/web03.jpg was not found on this server.<P>\n' +
    '</BODY></HTML>\n' +
    '\r\n' +
    '0\r\n' +
    '\r\n'
}

from undici.

KhafraDev avatar KhafraDev commented on July 20, 2024

I believe this was fixed

from undici.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.