我有一个生产中的Sinatra应用程序(使用Puma运行),其中包含一个not_found处理程序:
module MyApp
class Server
not_found do
[404, { 'Content-Type' => 'application/json' }, ['{"error":"not found"}']]
end
end
end
在开发中,这可以达到我的预期,在丢失的页面上,我看到404带有JSON错误消息。但是,在生产中我看到一个NotFound异常会触发Airbrake警报。
堆栈跟踪很长,但顶行指向此处:
/gems/sinatra-1.4.5/lib/sinatra/base.rb:1021 in "route_missing"
哪里在这里: https://github.com/sinatra/sinatra/blob/v1.4.5/lib/sinatra/base.rb#L1021,其中:
def route_missing
if @app
forward
else
raise NotFound
end
end
Sinatra源代码中的注释表示如果您的应用程序不是中间件,则会转发错误,否则会引发错误。但不知怎的,我的期望是我的not_found处理程序应该被调用。它正在开发中被称为。我怎样才能最好地调试它为什么不在生产中?