lib/easyship/middleware/error_handler_middleware.rb in easyship-0.1.2 vs lib/easyship/middleware/error_handler_middleware.rb in easyship-0.1.3

- old
+ new

@@ -27,12 +27,10 @@ def body_error(body) return {} unless body.is_a?(Hash) if body.key?(:error) && body[:error].is_a?(Hash) format_body_error(body) - elsif body.key?(:errors) && body[:errors].is_a?(Array) - format_body_errors_array(body) elsif body.key?(:errors) format_body_errors(body) else format_by_default(body) end @@ -44,15 +42,13 @@ def format_body_error(body) body[:error] end - def format_body_errors_array(body) - { details: body[:errors], message: body[:errors].map { |error| error[:message] }.join(', ') } - end - def format_body_errors(body) - { details: body[:errors], message: body[:errors] } + errors = Array(body[:errors]) + + { details: errors, message: errors.join(', ') } end def format_by_default(body) { details: body, message: 'Something went wrong.' } end