Code Monkey home page Code Monkey logo

Comments (5)

sindresorhus avatar sindresorhus commented on May 9, 2024

Can you run node with the --trace-warnings to get a stack trace?

from got.

Ocean15 avatar Ocean15 commented on May 9, 2024

Node is already running with trace-warnings flag. That's all stack trace we've got 😮‍💨

from got.

Ocean15 avatar Ocean15 commented on May 9, 2024

Without catching anything I get

Uncaught exception: RequestError: socket hang up
    at ClientRequest.<anonymous> (file:///XXXXXXXXX/node_modules/got/dist/source/core/index.js:792:107)
    at Object.onceWrapper (node:events:628:26)
    at ClientRequest.emit (node:events:525:35)
    at Socket.socketCloseListener (node:_http_client:469:11)
    at Socket.emit (node:events:525:35)
    at connResetException (node:internal/errors:718:14)
    at Socket.socketCloseListener (node:_http_client:469:25)
    at Socket.emit (node:events:525:35)
    at TCP.<anonymous> (node:net:320:12)

from got.

2snEM6 avatar 2snEM6 commented on May 9, 2024

This is happening to me as well when mocking an API with msw and returning a network error @sindresorhus :

import { graphql, HttpResponse, http } from 'msw';
import { setupServer } from 'msw/node';
import { got } from 'got';

let networkErrorCounter = 0;

const handlers = [
  http.get('https://unstable.com/v1/network-error', () => {
    if (networkErrorCounter === 0) {
      networkErrorCounter += 1;

      return HttpResponse.error();
    }

    return new HttpResponse(null, {
      status: 200,
    });
  }),
];

const server = setupServer(...handlers);

describe('got tests', () => {
    beforeAll(() => server.listen());
    afterEach(() => server.resetHandlers());
    afterAll(() => server.close());

    it('should retry requests on network error', async () => {
      const result = await got.get('https://unstable.com/v1/network-error');
      expect(result.statusCode).toBe(200);
      expect.assertions(1);
    });
});

Fails when running npx vitest with:

Error: socket hang up
 ❯ connResetException node:internal/errors:717:14
 ❯ _destroy node:_http_client:880:15
 ❯ TLSSocket.<anonymous> node:_http_client:897:11
 ❯ TLSSocket.<anonymous> node:internal/util:464:12
 ❯ onclose node:internal/streams/end-of-stream:148:25
 ❯ processTicksAndRejections node:internal/process/task_queues:77:11

image

from got.

2snEM6 avatar 2snEM6 commented on May 9, 2024

I am happy to provide a fully working reproducible example if needed but the above code snippet should work

from got.

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.