-
Notifications
You must be signed in to change notification settings - Fork 851
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
feat(logging): improve error message & add link to Node errors page. #106
Conversation
Hi @cloudmu, Thanks for the PR. I do like the improved error messaging. You already pointed out; Not sure about the extra Below I added two more variants of the error message. Original error message:
My preference would go to variant 3; If the goal is to make the error message less aggressive and more beginner friendly. For the following reasons:
|
@chimurai I like variant 3 too. Very clean. As I suggested in my original create-react-app PR, I was also thinking about a direct link to Nodejs common system error page, but wasn't sure how stable that link would stay. Was waiting on some feedback on preferences from other people, but want to get the ball rolling. For variant 3, I would probably still point out ECONNREFUSED to be errorcode, and put it on the same line with the link. So variant 4: |
Option 3 looks good to me. |
1 similar comment
} | ||
var errReference = 'https://nodejs.org/api/errors.html#errors_common_system_errors'; // link to Node Common Systems Errors page | ||
|
||
logger.error('[HPM] Error occurred while trying to proxy request %s from %s to %s (%s) \n(%s)', req.url, hostname, target, err.code, errReference); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need HPM here? If this is a transitive dependency people will be confused what it means.
HPM is used consistently as the source of logging for other logging levels, so it's a tough call. Some ideas:
I like option 2. but @chimurai it's your module, and your opinion counts most :-) |
Option 2 sounds good to me. |
@chimurai are you good with option 2 (changing HPM to http-proxy-middleware)? |
Option 2 looks good and it's definitely an improvement in HPM. But I still get the feeling this won't satisfy your original reason for creating this PR. I think, even with this change, it is still a bit too generic and vague for the create-react-app users. Another option you might want to explore is to configure a custom error handler. var proxy = require("http-proxy-middleware");
var onErrorHandler = function (err, req, res) {
console.log('Something went wrong.');
console.log('And we are reporting a custom error message.');
};
var options = {target:'http://localhost:3000', onError: onErrorHandler}; https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/proxy-events.md#onerror With a custom This custom |
|
||
logger.error('[HPM] PROXY ERROR: %s. %s -> %s', err.code, hostname, targetUri); | ||
logger.error('[HPM] Error occurred while trying to proxy request %s from %s to %s (%s) \n(%s)', req.url, hostname, target, err.code, errReference); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the line-break really needed?
I can imagine when you configure winston
in logProvider
to log to a file; those line-breaks will add a lot of visual noise as you go through the logs...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chimurai good point. I was only thinking console output in create-react-app. I looked there and line-break was used to break long lines.
I agree for the logging purpose we should remove the line-break. I can update the pull request. I understand with your onError suggestion, this pull request won't be necessary for create-react-app use case, but the error message does look a little better overall (plus Node error page link).
Also would you like to use [http-proxy-middleware] or keep [HPM]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can remove the line-break and keep [HPM]
this PR is good to go!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
I like the |
I totally missed the onError in the api. Should use that in the create-react-app use case! |
Thanks for the PR. Don't think you'll need a new version asap if you are using the |
@chimurai Yes, I am good. No release needed for now. Thanks for all the discussions and tips. |
This will add error description when logging errors.
HPM is used by create-react-app for Proxying API Requests. create-react-app expects more beginner friendly error messages. See pull request.