diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/tom_tom/matrix.rb | 19 | 
1 files changed, 18 insertions, 1 deletions
| diff --git a/lib/tom_tom/matrix.rb b/lib/tom_tom/matrix.rb index b0c8cc335..b57495f3f 100644 --- a/lib/tom_tom/matrix.rb +++ b/lib/tom_tom/matrix.rb @@ -20,11 +20,19 @@ module TomTom          req.body = build_request_body(points)        end +      matrix_json = JSON.parse(response.body) + +      check_for_error_response(matrix_json) +        extract_costs_to_way_costs!(          way_costs,          points_with_ids, -        JSON.parse(response.body) +        matrix_json        ) +    rescue RemoteError => e +      Rails.logger.error "TomTom::Matrix server error: #{e}" + +      []      end      def points_from_way_costs(way_costs) @@ -76,6 +84,12 @@ module TomTom        })      end +    def check_for_error_response(matrix_json) +      if matrix_json.has_key?('error') +        raise RemoteError, matrix_json['error']['description'] +      end +    end +      def extract_costs_to_way_costs!(way_costs, points, matrix_json)        way_costs = [] @@ -110,5 +124,8 @@ module TomTom        way_costs      end + + +    class RemoteError < RuntimeError; end    end  end | 
