diff options
| author | Alban Peignier | 2018-05-16 15:42:24 +0200 | 
|---|---|---|
| committer | GitHub | 2018-05-16 15:42:24 +0200 | 
| commit | 223d988ef59e562b201cac8391c397630c8953e5 (patch) | |
| tree | ecb43cdf1e461e621f8e5c22c5e5fdc2cd70b18d /lib/tom_tom/matrix.rb | |
| parent | 6f4d2a1954fa3b127785127e30f757f654fe20c7 (diff) | |
| parent | 9c442cd66c7d12266ba53e85949f775f6b842d2d (diff) | |
| download | chouette-core-223d988ef59e562b201cac8391c397630c8953e5.tar.bz2 | |
Merge pull request #553 from af83/6884-tomtom-matrix--handle-error-when-response-doesn,t-inclu
Handle API error(s) in Tomtom matrix. Fixes #6884
Diffstat (limited to 'lib/tom_tom/matrix.rb')
| -rw-r--r-- | lib/tom_tom/matrix.rb | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/lib/tom_tom/matrix.rb b/lib/tom_tom/matrix.rb index c418cd516..e779abbf7 100644 --- a/lib/tom_tom/matrix.rb +++ b/lib/tom_tom/matrix.rb @@ -4,6 +4,10 @@ module TomTom        @connection = connection      end +    # Exceptions: +    # +    # * This raises a `TomTom::Errors::MatrixRemoteError` when the API responds +    #   with an error.      def matrix(way_costs)        points_with_ids = points_from_way_costs(way_costs)        points = points_as_params(points_with_ids) @@ -21,6 +25,8 @@ module TomTom          req.body = build_request_body(points)        end +      check_for_error_response(response) +        extract_costs_to_way_costs!(          way_costs,          points_with_ids, @@ -77,6 +83,20 @@ module TomTom        })      end +    def check_for_error_response(response) +      if response.status != 200 +        raise TomTom::Errors::MatrixRemoteError, +          "status: #{response.status}, body: #{response.body}" +      end + +      json = JSON.parse(response.body) + +      if json.has_key?('error') +        raise TomTom::Errors::MatrixRemoteError, +          "status: #{response.status}, message: #{json['error']['description']}" +      end +    end +      def extract_costs_to_way_costs!(way_costs, points, matrix_json)        way_costs = [] | 
