-
Notifications
You must be signed in to change notification settings - Fork 43
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
Allow stringification of StatusCodeError errors to be disabled #1
Comments
Hi @Limess good point. I assume you only log the error message and maybe the stack trace but not the other error attributes like Let's talk about a quick fix first since your project probably demands a quick resolution. You may replace the whole var rp = require('request-promise') // request-promise may required first - no problem
// Replace the StatusCodeError during app boot time
var rpErrors = require('request-promise/errors')
rpErrors.StatusCodeError = MyCustomStatusCodeError
rp(...) // Your first request in your app - now uses your custom error implementation For Now about the proper fix: I agree, the error message is not the most brilliant one. We could of course just change it to "The request got a 404 response" or similar. But then it is not very insightful when encountered during development. What message would you use in your case which is more telling? |
Message is the only problematic attribute, we can easily control the logging of other attributes. We've done a quick fix of wrapping the library (already the case) and catching/re-throwing With regards to what information to instead place on the message, it's a difficult one without having detailed knowledge of what's 'safe' to add to the message which is beyond this library's role. We could provide a transform of the response but that might be overkill. Adding the status code string doesn't add much information either. I think we would leave this enabled in development, just disabled on production servers, so the obtuse message may not be a huge problem. |
I thought about it for a while and suggest this:
Sounds good @Limess ? |
@analog-nico may I make a PR for this? Also why is |
@gurpreetatwal Of course, go ahead. To potentially save you some rework how do you intent to design the feature in terms how a user will use it?
|
@analog-nico I think I might have misunderstood the solution you suggested. From my understanding the only changes that would be required would be:
|
@gurpreetatwal Oh sorry, I forgot that I already proposed a solution. Absolutely, go ahead with that. Thanks for your contribution! |
In terms of the Assigning the response body to rp.get(...).catch(StatusCodeError, function(err) {
const detail = err.error.error.detail;
}) Given that the request responds with {
"error": {
"detail": "...."
}
} |
True, quirky. It’s also legacy from <0.4. I didn’t introduce a |
Ah gotcha, makes sense Any preference for what StatusCodeError's message should be? I was thinking it would be cool if the message matched the description for the error encountered, it provides some information useful information when logged, but doesn't have the potential to reveal anything sensitive. However, this would require having to maintain a mapping of code -> message and updating that as needed. |
Good idea. "404 - Not Found" etc. You may use |
Why is the error lib even modifying the message to begin with? I am passing a specific message along with the error and then this library modifies the message. I am having to do string manipulation just to get the original message I wanted out of it. Is there a way to modify the error in a way that adds the information you are attempting to add to it, without modifying the message at all? |
@awitherow Might the error properties make your life easier? E.g. |
very nice @analog-nico thanks! |
Hello,
We have quite strict data-protection requirements regarding what can be logged to disk. When a
StatusCodeError
is logged, the error is currently thrown with a message which contains the whole stringified body (promise-core/lib/errors.js
Line 26 in c377e5c
Would it be possible to add an option to disable this behaviour (as the body is still acceptable on the error object)?
The text was updated successfully, but these errors were encountered: