关于api:Ruby救援语法错误

Ruby rescue syntax error

我有以下代码行给出了一个错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
rescue Timeout::Error => e
    logs.puts("Rescued a timeout error...#{e}")
    email_ids_all.each do |email_delete|

      call="/api/v2/emails/#{email_delete}/"
      uri= HTTParty.delete("https://www.surveys.com#{call}",
          :basic_auth => auth,
          :headers => { 'ContentType' => 'application/x-www-form-urlencoded', 'Content-Length' =>"0" }
      )
      puts"Deleted email #{email_delete}".green
      log.puts("Deleted email #{email_delete}")
    end
    abort #abort entire script after deleting emails
  end

我收到的错误是这样的:

1
2
3
syntax error, unexpected keyword_rescue, expecting $end
  rescue Timeout::Error => e
        ^

基本上我只是尝试在脚本超时时运行API删除调用。 虽然我在rescue的块中放入了什么并不重要,但是我收到了同样的错误。 我在rescue方法上的语法有什么问题?


使用rescue的格式如下:

1
2
3
4
5
6
7
8
9
10
11
begin
  # Code you want to run that might raise exceptions
rescue YourExceptionClass => e
  # Code that runs in the case of YourExceptionClass
rescue ADifferentError => e
  # Code that runs in the case of ADifferentError
else
  # Code that runs if there was no error
ensure
  # Code that always runs at the end regardless of whether or not there was an error
end

这是一个包含更多信息的问题:Ruby中的Begin,Rescue和Ensure?