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

Expose "jse_shortmsg" publicly #70

Open
WangHansen opened this issue Jul 15, 2019 · 4 comments
Open

Expose "jse_shortmsg" publicly #70

WangHansen opened this issue Jul 15, 2019 · 4 comments

Comments

@WangHansen
Copy link

This is exactly the same request as the #52.

The use case is that I want to capture the entire error with all the causes for debugging, logging and other purposes. But when I return the JSON back to the client. I only want the user to see what is in the "jse_shortmsg".

For example:

// Example error from third-party library
const originalError = new MongoError("Duplicate keys detected")

// Example error I handle on my server
const error = VError(originalError, "Failed to update record")

// This would log: "Failed to update record: Duplicate keys detected"
logger.log(error.message)

// I only want user to see "Failed to update record"
res.json({ message: error["jse_shortmsg"] })
@davepacheco
Copy link
Contributor

The conclusion in #52 was to use the WError class for this. Does that not do what you want?

@WangHansen
Copy link
Author

@davepacheco Sorry I should have mentioned this. Yes, I did look at #52. The problem with using WError is that I lose the ability to get the chained message by calling error.message if I understand correctly.

The solution I was looking for is to provide a way to get both the chained long error message and the short version as well. It seems that with VError or WError, I can get either a short or a long version but not both.

@davepacheco
Copy link
Contributor

Thanks for clarifying. I haven't thought about it much but it seems like we could add a method to WError to get the long message. I prefer that slightly to adding a short message to VError but either may be okay.

@WangHansen
Copy link
Author

No problem, thanks so much for all the hard work, this is an amazing library!

I would prefer just adding it to VError just because I am mostly using VError throughout my code and I guess it would be the same for a lot of other developers. Maybe I am wrong. Works either way.

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