Skip to content

Commit

Permalink
Updates to the error handling to include parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jufemaiz committed Feb 6, 2014
1 parent e423581 commit 8d8974d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/pipedrive/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def authenticate(token)
# Examines a bad response and raises an appropriate exception
#
# @param [HTTParty::Response] response
def bad_response(response)
def bad_response(response, params={})
if response.class == HTTParty::Response
raise HTTParty::ResponseError, response
raise HTTParty::ResponseError, "#{response}\n params: #{params.inspect}"
end
raise StandardError, 'Unknown error'
end
Expand All @@ -87,7 +87,7 @@ def all(response = nil, options={})
if res.ok?
res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
else
bad_response(res)
bad_response(res,attrs)
end
end

Expand All @@ -97,18 +97,18 @@ def create( opts = {} )
res['data'] = opts.merge res['data']
new(res)
else
bad_response(res)
bad_response(res,opts)
end
end

def find(id)
res = get "#{resource_path}/#{id}"
res.ok? ? new(res) : bad_response(res)
res.ok? ? new(res) : bad_response(res,id)
end

def find_by_name(name, opts={})
res = get "#{resource_path}/find", :query => { :term => name }.merge(opts)
res.ok? ? new_list(res) : bad_response(res)
res.ok? ? new_list(res) : bad_response(res,{:name => name}.merge(opts))
end

def resource_path
Expand Down
4 changes: 2 additions & 2 deletions lib/pipedrive/deal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Deal < Base

def add_product(opts = {})
res = post "#{resource_path}/#{id}/products", :body => opts
res.success? ? res['data']['product_attachment_id'] : bad_response(res)
res.success? ? res['data']['product_attachment_id'] : bad_response(res,opts)
end

def products
Expand All @@ -12,7 +12,7 @@ def products

def remove_product product_attachment_id
res = delete "#{resource_path}/#{id}/products", { :body => { :product_attachment_id => product_attachment_id } }
res.success? ? nil : bad_response(res)
res.success? ? nil : bad_response(res,product_attachment_id)
end

def activities
Expand Down
2 changes: 1 addition & 1 deletion lib/pipedrive/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def stages
def statistics(id, start_date, end_date)
res = get("#{resource_path}/#{id}/movement_statistics",
:query => {:start_date => start_date, :end_date => end_date})
res.ok? ? new(res) : bad_response(res)
res.ok? ? new(res) : bad_response(res,{:id=>id,:start_date=>start_date,:end_date=>end_date})
end

def deals(id, stage_id)
Expand Down
4 changes: 2 additions & 2 deletions lib/pipedrive/search-result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def search(term, start=0, limit=nil)
if res.ok?
res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
else
bad_response(res)
bad_response(res,{:term=>term,:start=>start,:limit=>limit})
end
end

Expand All @@ -18,7 +18,7 @@ def field(term, field_type, field_key, opts={})
if res.ok?
res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
else
bad_response(res)
bad_response(res,{:term=>term,:field_type=>field_type,:field_key=>field_key},merge(opts))
end
end

Expand Down

0 comments on commit 8d8974d

Please sign in to comment.