class Zerobounce::Error
The base Zerobounce
error.
@author Aaron Frase
Attributes
env[R]
Public Class Methods
from_response(env)
click to toggle source
Parse the response for errors.
@param [Hash] env @return [Error, nil]
# File lib/zerobounce/error.rb, line 22 def from_response(env) case env[:status] when 500 parse500(env) when 200 parse200(env) else UnknownError.new(env) end end
new(env={})
click to toggle source
Calls superclass method
# File lib/zerobounce/error.rb, line 12 def initialize(env={}) @env = env super(env[:body]) end
Private Class Methods
parse200(env)
click to toggle source
@param [Hash] env @return [Error, nil]
# File lib/zerobounce/error.rb, line 47 def parse200(env) # The body hasn't been parsed yet and to avoid potentially parsing the body twice # we just use String#start_with? ApiError.new(env) if env[:body].to_s.start_with?('{"error":') end
parse500(env)
click to toggle source
@param [Hash] env @return [Error]
# File lib/zerobounce/error.rb, line 37 def parse500(env) if env[:body].to_s.start_with?('Missing parameter') MissingParameter.new(env) else InternalServerError.new(env) end end