Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## patch for retrying post and throwing an error upon failure in Facebooker::Service::CurlService::post_form
- def post_form(url,params,multipart=false)
- tries = 2
- begin
- curl = Curl::Easy.new(url.to_s) do |c|
- c.multipart_form_post = multipart
- c.timeout = 2 #second.. Facebooker.timeout
- end
- curl.http_post(*to_curb_params(params))
- curl.body_str
- rescue Curl::Err::TimeoutError => e
- tries -= 1
- sleep 0.1
- if tries > 0
- retry
- else
- raise Errno::ECONNRESET
- end
- rescue Curl::Err::GotNothingError => e
- tries -= 1
- sleep 0.1
- if tries > 0
- retry
- else
- raise Errno::ECONNRESET
- end
- end
- end
- ## or you can remove the retry logic from post_form since Facebooker::Service::post has retry logic
- def post_form(url,params,multipart=false)
- begin
- curl = Curl::Easy.new(url.to_s) do |c|
- c.multipart_form_post = multipart
- c.timeout = 2 #second.. Facebooker.timeout
- end
- curl.http_post(*to_curb_params(params))
- curl.body_str
- rescue Curl::Err::TimeoutError => e
- raise Errno::ECONNRESET
- rescue Curl::Err::GotNothingError => e
- raise Errno::ECONNRESET
- end
- end
Add Comment
Please, Sign In to add comment