mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Yield error in custom error handlers
This commit is contained in:
parent
14b094d52f
commit
012ac8f6b7
5 changed files with 40 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue