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

No way to get the original *non-error thrown* message #19

Closed
JounQin opened this issue Jan 31, 2017 · 2 comments
Closed

No way to get the original *non-error thrown* message #19

JounQin opened this issue Jan 31, 2017 · 2 comments

Comments

@JounQin
Copy link

JounQin commented Jan 31, 2017

Notice https://github.com/koajs/onerror/blob/master/index.js#L35

I'm using server slide render with koa, what means Error will be thrown from a bundler file, then the Error instance is not an instance of node Error.

Then what if I just throw {status: 404}, follow the code it will be transformed to non-error thrown: [Object object], so there will be no way to get the original error message!

Should we just delete this line of code or find another way?

@JounQin
Copy link
Author

JounQin commented Jan 31, 2017

How about this:

if (!(err instanceof Error)) {
  const originalError = err
  let errMsg = 'non-error thrown: '
  try {
    errMsg += JSON.stringify(err);
  } catch (e) {
    errMsg += err
  }
  err = new Error(errMsg);
  err.originalError = originalError
  typeof originalError === 'object' && Object.assign(err, originalError)
}

@dead-horse
Copy link
Member

The latest version resolved your problem. https://github.com/koajs/onerror/blob/master/index.js#L38

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

No branches or pull requests

2 participants