【发布时间】:2021-02-28 19:00:01
【问题描述】:
您好,我有一个从 Hubspot 提取信息的服务类。
module HubspotApi
class CompanyImporter < ApplicationService
MAX_RETRIES = 3
def initialize(company_vid)
@company_vid = company_vid
@attempt = 0
end
def service_body
imported_profile
end
private
attr_reader :company_vid, :attempt
def imported_profile
## load hubspot record over here and take other actions
end
def hubspot_record
@hubspot_record ||= Hubspot::Company.find_by_id(company_vid.to_i)
rescue Hubspot::RequestError
if (attempt += 1) <= MAX_RETRIES
sleep 2**attempt
retry
else
@messages << 'Raise some hubspot error'
end
end
end
end
我尝试使用不正确的 company_vid 调用它,以确保重试正常工作,但我不断收到错误消息:
NoMethodError: undefined method `+' for nil:NilClass from `rescue in hubspot_record'
Caused by Hubspot::RequestError: Response body: {"status":"error","message":"resource not found"}
我不确定我是否在这里放屁,但我无法确定这里的错误,因为应该定义变量
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-5