0

What I'd like to do is:

error 400..510 do
    {:'400' => 'Bad Request', :'401' => ...}[<http-status-code>.to_s.to_sym]
end

where <http-status-code> is some expression, evaluated to error code to be returned. One possible way the handler is triggered:

get '/test' do
    401
end

Is this achievable?

x-yuri
  • 16,722
  • 15
  • 114
  • 161

1 Answers1

0

You can send a Net::HTTP request. The output of that request will be a Net::HTTPResponse object. For example, from the Ruby Net::HTTP documentation at http://ruby-doc.org/stdlib-2.0.0/libdoc/net/http/rdoc/Net/HTTP.html:

uri = URI('http://example.com/index.html')
res = Net::HTTP.get_response(uri)
res.code
elreimundo
  • 6,186
  • 1
  • 13
  • 6
  • You must be getting me wrong. I'm trying to determine status code of _current request_. And if you're suggesting to make subrequest to determine status code, that would be overkill. (I've slightly updated the question.) – x-yuri Nov 16 '13 at 18:33