Skip to content

Got throws if passed options are already frozen #1050

@gautaz

Description

@gautaz

Describe the bug

Currently the snippet provided in the code to reproduce section fails.

got tries to mutate the options object. This currently impacts test scenarii where the same options object is used between different tests.

Actual behavior

> node .

(node:12424) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'body' of undefined
    at /home/user/dev/got-issue/index.js:12:32
(node:12424) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:12424) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected behavior

No mutation.

Code to reproduce

const got = require('got');
const options = {};

Object.freeze(options);

(async () => {
  try {
    const response = await got('https://sindresorhus.com', options);
    console.log(response.body);
    //=> '<!doctype html> ...'
  } catch (error) {
    console.log(error.response.body);
    //=> 'Internal server error ...'
  }
})();

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions