Yield error in custom error handlers

This commit is contained in:
sdogruyol 2016-11-16 20:27:01 +03:00
parent 14b094d52f
commit 012ac8f6b7
5 changed files with 40 additions and 11 deletions

View file

@ -80,4 +80,26 @@ describe "Kemal::CommonExceptionHandler" do
response.headers["Content-Type"].should eq "application/json"
response.body.should eq "Something happened"
end
it "renders custom error with env and error" do
error 500 do |env, err|
err.message
end
get "/" do |env|
env.response.content_type = "application/json"
env.response.status_code = 500
end
request = HTTP::Request.new("GET", "/")
io = MemoryIO.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
Kemal::CommonExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE
Kemal::CommonExceptionHandler::INSTANCE.call(context)
response.close
io.rewind
response = HTTP::Client::Response.from_io(io, decompress: false)
response.status_code.should eq 500
response.headers["Content-Type"].should eq "application/json"
response.body.should eq "Rendered error with 500"
end
end