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

HTTPResponseError code in "Handling client and server errors" section is incorrect. #1138

Open
craigklem opened this issue Apr 28, 2021 · 2 comments

Comments

@craigklem
Copy link

Sample code provided for "Handling client and server errors" section on main page is invalid. See: https://github.com/node-fetch/node-fetch#handling-client-and-server-errors

class HTTPResponseError extends Error {
	constructor(response, ...args) {
		this.response = response;
		super(`HTTP Error Response: ${response.status} ${response.statusText}`, ...args);
	}
}
  1. trying to use code will fail with runtime exception. WebStorm shows problem: 'this' is not allowed before superclass constructor invocation.
  2. ..args should be removed, node Error constructor only supports a single string argument. See: https://nodejs.org/docs/latest-v10.x/api/errors.html#errors_new_error_message

Reproduction

Steps to reproduce the behavior:

  1. Copy and use sample code from "Handling client and server errors" section.

Expected behavior
Modified code that works should be like:

class HTTPResponseError extends Error {
	constructor(response) {
		super(`HTTP Error Response: ${response.status} ${response.statusText}`);
		this.response = response;
	}
}

Screenshots

Your Environment

software version
node-fetch 2.6.1
node 14.15.4
npm 6.14.11
Operating System Windows 10

Additional context

@craigklem craigklem added the bug label Apr 28, 2021
@xxczaki xxczaki added the doc label May 4, 2021
@dhananjaysa92
Copy link
Contributor

looking into this issue

@dhananjaysa92
Copy link
Contributor

PR created - #1666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants