Back

ruby - sinatra - 默认不要显示 exception信息 sinatra donot show exception stack

发布时间: 2022-10-14 01:39:00

refer to:
https://stackoverflow.com/questions/26233926/sinatra-error-handling

在app.rb 中加上:

configure :development do 
    disable :show_exceptions  
end

然后运行:

RACK_ENV=production  ruby app.rb 

就可以了。

另外,也可以使用这样的方式:

get '/hi' do 
    begin 
       "ok"
    rescue 
       "failed"
    end
end

另外,也可以定制显示 404, 500错误:


问题出现的原因:不希望用户看到我们的默认sinatra页面(会暴露一系列的环境信息,而且不专业)

解决办法:

https://www.google.com/search?client=firefox-b-d&q=sinatra+error+page

https://stackoverflow.com/questions/19781051/rendering-404-in-sinatra-if-file-not-found

https://github.com/sinatra/sinatra/issues/1191

Back