sinatra - 如何使用 Sinatra 服务 500 个页面?

标签 sinatra rack

由于Sintra是一个Rack应用程序,我认为它可以使用Rack方式:

get '/' do
      result = true
      if result 
             ['200', {'Content-Type' => 'application/json'}, [{result:true}.to_  json]]
         else
             binding.pry
             ['500', {'Content-Type' => 'application/json'}, [{result:false}.to  _json]] 
         end    
end  

它不起作用,它总是返回一个 500 页面,无论变量是 true 还是 false

最佳答案

如果您的应用程序中确实有此文字代码:

{result:true}.to_  json # <<< whitespace that shouldn't be there

那么你的代码将会出现运行时异常(可能缺少方法 to_未知变量或方法 json),这就是为什么你每次都会收到 500 错误。

关于sinatra - 如何使用 Sinatra 服务 500 个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16194851/

相关文章:

sinatra - 瘦和 sinatra - 如何停止/重新启动?没有瘦.pid

ruby-on-rails - 如何关闭 Rack 应用程序?

ruby - 在 Sinatra 中故意引发 500 个错误以测试它们的处理方式

mysql - 未定义方法 `bytesize' for {"COUNT(*)"=>0} :Hash

postgresql - 空的、不可编辑的 pg_hba.conf 文件

ruby-on-rails - Sinatra 有 ActiveMerchant 吗?

css - 样式表不适用于 sinatra erb View

ruby - 在 Rack 应用程序中返回由换行符分隔的字符串

ruby - Unicorn 认为什么是 "fast"和 "slow"请求?

ruby - 在 Rack 应用程序(Grape API)中使用 CORS 和 Warden