I'm trying to handle errors nicely using Sinatra. For example, say I have a block like this:
get '/auth/' do
...
begin
access_token_obj = OAuth2::AccessToken.new(client, token)
rescue OAuth2::Error => e
return 403, e.description
rescue
return 403, "Something went wrong"
end
...
end
I want to display a nice error page to the user. The Sinatra docs suggest I can do something like:
error 403 do
"Access forbidden"
end
But how do I get the error message ("Something went wrong" or e.description) to display to the user? In my error 403 do block there is no env['sinatra.error'] available. I'm obviously missing something (I'm a bit new to ruby).