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

Support plain objects #3

Merged
merged 6 commits into from
Dec 26, 2018

Conversation

felixfbecker
Copy link
Contributor

@felixfbecker felixfbecker commented Dec 21, 2017

Love the idea of this module.
I currently have a lot of code that does REST or GraphQL API calls, where in error cases the API usually returns one or multiple error objects with a message property and possibly others like name, code etc. They are of course not Error instances, and currently get treated as new Error(err), which creates an Error with message [object Object].

This PR makes it so that if the passed error is not an Error instance, but an object, an Error is created with err.message as the message and all metadata properties copied over to the Error object.

@felixfbecker felixfbecker force-pushed the plain-error-objects branch 2 times, most recently from c5c03b7 to 3ba0093 Compare December 21, 2017 20:28
@felixfbecker
Copy link
Contributor Author

@sindresorhus would you mind taking a look at this?

index.js Show resolved Hide resolved
@sindresorhus
Copy link
Owner

I'm on the fence about this one as it feels wrong to accept arbitrary objects, but JS is arbitrary, so I guess it's ok.

@sindresorhus
Copy link
Owner

This will also need readme updates.

@felixfbecker
Copy link
Contributor Author

I'm on the fence about this one as it feels wrong to accept arbitrary objects, but JS is arbitrary, so I guess it's ok.

Duck typing FTW 🦆

@felixfbecker
Copy link
Contributor Author

Updated the README

@felixfbecker
Copy link
Contributor Author

Speaking of typing, would you accept a TypeScript declarations file?

@sindresorhus sindresorhus changed the title Support plain error objects with message property Support plain error objects Dec 26, 2018
@sindresorhus sindresorhus changed the title Support plain error objects Support plain objects Dec 26, 2018
@sindresorhus
Copy link
Owner

Speaking of typing, would you accept a TypeScript declarations file?

Yup, just ensure you follow https://github.com/sindresorhus/typescript-definition-style-guide

@sindresorhus
Copy link
Owner

Sorry, this PR got lost in my open tabs...

@sindresorhus sindresorhus merged commit 156215d into sindresorhus:master Dec 26, 2018
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.

2 participants