如何捕捉Sinatra :: NotFound?

时间:2016-04-19 11:43:31

标签: exception exception-handling sinatra

http://rollbar.com是错误跟踪服务。 更新

我在信息中心找到了此网址 - http://52.38.72.163/robots.txt。看来我需要更改nginx配置
机器人来到我的生产现场并导致Sinatra :: NotFound。

我试着像这样修理它:

application.rb中

 class Application < Sinatra::Base
   def route_missing
     if @app
       forward
     else
       halt 404, 'Not found'
     end
   end        
   # also tried this
   error Sinatra::NotFound do
     'Route not found'
   end
 end

我仍然收到有关此错误的邮件。
有谁遇到过这个问题?任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

您是否尝试过以下操作?

class App < Sinatra::Base

    set :raise_errors, false
    set :show_exceptions, false

    error do
        redirect to('/') # or something else
    end

答案 1 :(得分:0)

我阻止了nginx级别的IP访问

nginx的/启用的站点 - / ... CONF

server {
  // other configurations
  if ($host = "52.38.72.163") {
      return 404;
  }
}