1

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

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

4

1 回答 1

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
于 2013-10-11T07:47:09.557 回答