diff --git a/CHANGELOG.md b/CHANGELOG.md index c41ba17..5243249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ This file is a manually maintained list of changes for each release. Feel free to add your changes here when sending pull requests. Also send corrections if you spot any mistakes. +## v2.0.4 (2015-12-18) +* Better exception and error handling + ## v2.0.3 (2015-12-09) * Added campaign resource's merge call, for propagating campaign pass data changes to all of it's passes. diff --git a/lib/passworks/faraday/http_exception_middleware.rb b/lib/passworks/faraday/http_exception_middleware.rb index 1c69581..a83ad20 100644 --- a/lib/passworks/faraday/http_exception_middleware.rb +++ b/lib/passworks/faraday/http_exception_middleware.rb @@ -47,7 +47,7 @@ def initialize(app) private def error_400(response) - "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]} - #{error_body(response)}" + "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}\n#{error_body(response)}" end def error_500(response, short_description, long_description) @@ -63,8 +63,8 @@ def error_body(response) if body.nil? nil - elsif body['message'] - "(#{body['error_code']}) #{body['message']}" + elsif body['errors'] + body['errors'].collect{ |k,v| "#{k}: #{v.join(',')}" }.join("\n") end end diff --git a/lib/passworks/request.rb b/lib/passworks/request.rb index af8d26f..022733b 100644 --- a/lib/passworks/request.rb +++ b/lib/passworks/request.rb @@ -24,8 +24,8 @@ def agent connection.use Passworks::Faraday::HttpExceptionMiddleware connection.adapter ::Faraday.default_adapter end - @agent.headers[:user_agent] = @user_agent - # always return the {@agent} + @agent.headers[:user_agent] = @user_agent + @agent.headers['Content-Type'] = 'application/json' @agent end diff --git a/lib/passworks/version.rb b/lib/passworks/version.rb index 7800197..e361bce 100644 --- a/lib/passworks/version.rb +++ b/lib/passworks/version.rb @@ -1,3 +1,3 @@ module Passworks - VERSION = "2.0.3" + VERSION = "2.0.4" end \ No newline at end of file