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

Set HttpError name to be HttpError #4911

Merged
merged 2 commits into from
Jun 10, 2020
Merged

Set HttpError name to be HttpError #4911

merged 2 commits into from
Jun 10, 2020

Conversation

jesseshieh
Copy link
Contributor

While trying to use error.name, I noticed that the HttpError used by react-admin has its name set to Error instead of HttpError. I believe this is probably due to microsoft/TypeScript#14099

Setting it explicitly seems like it would be fine in this case, but let me know if you prefer a different solution.

Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

The recommendation from https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work is to manually adjust the prototype immediately after any super(...) calls:

class FooError extends Error {
    constructor(m: string) {
        super(m);

+       // Set the prototype explicitly.
+       Object.setPrototypeOf(this, FooError.prototype);
    }

    sayHello() {
        return "hello " + this.message;
    }
}

Could you do that instead?

@jesseshieh
Copy link
Contributor Author

np, done

@djhi djhi added this to the 3.6.1 milestone Jun 10, 2020
@djhi
Copy link
Collaborator

djhi commented Jun 10, 2020

Thanks!

@djhi djhi merged commit a334deb into marmelab:master Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants