Error Handling

Houston, we have a problem

The error macro allows you to define a handler for a specific status code. The associated block can take the context (ctx) and any exceptions (ex).

error 404 do |ctx, ex|
  puts "ex: #{ex}"
  ctx.response.content_type = "text/plain"
  ctx.response.status_code = 404
  "Aww shucks. Page not found :("
end