【问题标题】:How to raise 505 exception in ruby on rails in development?如何在开发中的 ruby​​ on rails 中引发 505 异常?
【发布时间】:2013-10-19 04:37:34
【问题描述】:

有没有办法在开发中使用 ruby​​ on rails 引发 505 异常?

我想测试我的自定义 505 异常,但没有找到有关如何在任何地方引发 505 的文档。

【问题讨论】:

    标签: ruby-on-rails exception ruby-on-rails-4 raise


    【解决方案1】:

    我在这里有点困惑。你说的是 505 状态码吗?还是您在谈论引发异常?

    我不认为有 505 异常,所以我假设您说的是不支持 HTTP 状态代码版本 (http://en.wikipedia.org/wiki/List_of_HTTP_status_codes)。

    可以这么简单:

      def index
        render nothing: true, status: 505
      end
    

    如果你调用这样的动作,你会得到这样的响应:

    curl -I http://hamburg.onruby.dev:5000/
    HTTP/1.1 505 HTTP Version not supported
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    X-UA-Compatible: chrome=1
    Content-Type: text/html; charset=utf-8
    X-Meta-Request-Version: 0.2.8
    Cache-Control: no-cache
    Set-Cookie: locale=de; domain=onruby.dev; path=/; expires=Sat, 11 Oct 2014 07:45:52 -0000
    X-Request-Id: b8232480-5585-4e99-bc4c-44019e41db6a
    X-Runtime: 0.010615
    Connection: close
    Server: thin 1.5.1 codename Straight Razor
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      相关资源
      最近更新 更多