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

Revamp unavailable session response message #109

Merged
merged 1 commit into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/web_console/middleware.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'active_support/core_ext/string/strip'

module WebConsole
class Middleware
TEMPLATES_PATH = File.expand_path('../templates', __FILE__)
Expand All @@ -7,6 +9,13 @@ class Middleware
binding_change_re: %r{/repl_sessions/(?<id>.+?)/trace\z}
}

UNAVAILABLE_SESSION_MESSAGE = <<-END.strip_heredoc
Session %{id} is is no longer available in memory.

If you happen to run on a multi-process server (like Unicorn) the process
this request hit doesn't store %{id} in memory.
END

cattr_accessor :whiny_requests
@@whiny_requests = true

Expand Down Expand Up @@ -73,7 +82,7 @@ def id_for_repl_session_stack_frame_change(request)

def update_repl_session(id, params)
unless session = Session.find(id)
return respond_with_unavailable_session
return respond_with_unavailable_session(id)
end

status = 200
Expand All @@ -85,7 +94,7 @@ def update_repl_session(id, params)

def change_stack_trace(id, params)
unless session = Session.find(id)
return respond_with_unavailable_session
return respond_with_unavailable_session(id)
end

session.switch_binding_to(params[:frame_id])
Expand All @@ -97,10 +106,10 @@ def change_stack_trace(id, params)
Rack::Response.new(body, status, headers).finish
end

def respond_with_unavailable_session
def respond_with_unavailable_session(id)
status = 404
headers = { 'Content-Type' => 'application/json; charset = utf-8' }
body = { output: 'Unavailable session' }.to_json
body = { output: format(UNAVAILABLE_SESSION_MESSAGE, id: id)}.to_json

Rack::Response.new(body, status, headers).finish
end
Expand Down
4 changes: 2 additions & 2 deletions test/web_console/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def call(env)
test 'unavailable sessions respond to the user with a message' do
xhr :put, '/repl_sessions/no_such_session', { input: '__LINE__' }

assert_equal({ output: 'Unavailable session' }.to_json, response.body)
assert_equal(404, response.status)
end

test 'unavailable sessions can occur on binding switch' do
xhr :post, "/repl_sessions/no_such_session/trace", { frame_id: 1 }

assert_equal({ output: 'Unavailable session' }.to_json, response.body)
assert_equal(404, response.status)
end

private
Expand Down