Skip to content

Instantly share code, notes, and snippets.

@mitsuru793
Created October 12, 2015 06:57
Show Gist options
  • Select an option

  • Save mitsuru793/a2dac5d4f83258a94d85 to your computer and use it in GitHub Desktop.

Select an option

Save mitsuru793/a2dac5d4f83258a94d85 to your computer and use it in GitHub Desktop.
503エラーの時に再接続する
require 'open-uri'
# 末尾に記述した数値のステータスコードを返してくれるwebサービス
url = 'http://ozuma.sakura.ne.jp/httpstatus/503'
def open_url(url)
begin
open(url)
rescue OpenURI::HTTPError => e
response = e.io
# response.status => ["503", "Service Unavailable"]
if response.status[0] == "503"
puts "retry open"
open_url(url)
end
end
end
open_url(url)
# => retry open
# retry open
# retry open
# 以下ループ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment