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

Show an error message when an error response does not have JSON #157

Merged
merged 4 commits into from
Aug 14, 2015

Conversation

sh19910711
Copy link

After stopping a web server, the console is not doing anything even if a user types commands. It might cause a little confusion to the users.

This pull request is to show an error message in such that case, and also show a HTTP status code when an error response does not have a JSON-formatted text (see the test case: fb979f8).

Example
>> input
=> result
( stop web server )
>> input
ERROR: connection is refused
GIF: start server => stop server => restart server

GIF


Thanks.

function handleMessage(req, sender, sendResponse) {
if (req.type === 'request') {
var url = tabInfo[req.tabId].remoteHost + '/' + req.url;
REPLConsole.request(req.method, url, req.params, function(xhr) {
sendResponse({ status: xhr.status, responseText: xhr.responseText });
sendResponse(extractProps(xhr));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to use xhr.statusText.

@gsamokovarov
Copy link
Collaborator

Didn't we issue the message before? Also most of the messages we currently have are pretty prosaic. I think its okay to drop the ERROR: prefix and just drop a sentence with a hint of what's going on.

@sh19910711 sh19910711 force-pushed the patch/0020/show-error-message branch 3 times, most recently from f490f58 to 2871284 Compare August 12, 2015 03:20
@sh19910711
Copy link
Author

OK, updated:

And here is a diff of the message:

- ERROR: connection is refused
+ Oops! Failed to connect to Web Console middleware.
+ Please make sure that web server is running.

Thanks!

@gsamokovarov
Copy link
Collaborator

Add a fix for the test:templates rake task (ref

Can we move this to its own PR?

@sh19910711
Copy link
Author

Can we move this to its own PR?

OK, I have moved it.


function getErrorText(xhr) {
if (!xhr.status) {
return "Oops! Failed to connect to Web Console middleware.\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a good idea to collect all the messages we have and put them in config/locale/en.yml or something like this. It will open the door for internationalization and will get rid of those hard-coded messages from the code-base. Just some food for thought.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's do it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be my native language parasite skills kicking in, but maybe we can reword the following sections:

- connect to Web Console
+ connect to the Web Console

... and:

- Please make sure that web server is running.
+ Please make sure a rails development server is running.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a valuable point to me :-)

@gsamokovarov
Copy link
Collaborator

Let's make a final message pass and this PR is good to go. 👍

@sh19910711 sh19910711 force-pushed the patch/0020/show-error-message branch from 87ab763 to 4575a2b Compare August 14, 2015 07:48
@sh19910711
Copy link
Author

Updated:

  • Move WebConsole::Template::Context into WebConsole::View (ref: ad17a5a)
    • We can reuse it on the FakeMiddleware class as well.
  • Use I18n module for system messages instead of hard-coded value (ref: fb55d48)
    • Put the messages in config/locales/en.yml

Thank you!

@@ -0,0 +1,2 @@
require 'active_support/core_ext/string/access'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for doing this!

You can actually put it inside an initializer in the Railtie.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually put it inside an initializer in the Railtie.

OK, I will change it.

@sh19910711 sh19910711 force-pushed the patch/0020/show-error-message branch from 4575a2b to 0f47ed9 Compare August 14, 2015 09:20
@sh19910711
Copy link
Author

Updated again ♻️

  • Move lib/web_console/config/locales into lib/config/locales
  • Move the i18n configuration into railtie.rb
    • but I'm not sure I'm doing it correctly, so let me know if I'm mistaking.

Thanks.

@@ -66,5 +66,9 @@ class Railtie < ::Rails::Railtie
Middleware.whiny_requests = config.web_console.whiny_requests
end
end

initializer 'i18n.load_path' do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly that, yes! 👍

@gsamokovarov
Copy link
Collaborator

Thanks a lot!

gsamokovarov added a commit that referenced this pull request Aug 14, 2015
Show an error message when an error response does not have JSON
@gsamokovarov gsamokovarov merged commit ba5a850 into rails:master Aug 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants