diff options
| -rw-r--r-- | app/services/route_way_cost_calculator.rb | 2 | ||||
| -rw-r--r-- | lib/tom_tom/errors.rb | 4 | ||||
| -rw-r--r-- | lib/tom_tom/errors/matrix_remote_error.rb | 5 | ||||
| -rw-r--r-- | lib/tom_tom/matrix.rb | 9 | ||||
| -rw-r--r-- | lib/tom_tom/matrix/remote_error.rb | 5 | ||||
| -rw-r--r-- | spec/lib/tom_tom/matrix_spec.rb | 8 | 
6 files changed, 19 insertions, 14 deletions
| diff --git a/app/services/route_way_cost_calculator.rb b/app/services/route_way_cost_calculator.rb index 58f9ad1d0..ca47a6772 100644 --- a/app/services/route_way_cost_calculator.rb +++ b/app/services/route_way_cost_calculator.rb @@ -8,7 +8,7 @@ class RouteWayCostCalculator      way_costs = TomTom.matrix(way_costs)      way_costs = WayCostCollectionJSONSerializer.dump(way_costs)      @route.update(costs: way_costs) -  rescue TomTom::Matrix::RemoteError => e +  rescue TomTom::Errors::MatrixRemoteError => e      Rails.logger.error "TomTom::Matrix server error: #{e}"    end  end diff --git a/lib/tom_tom/errors.rb b/lib/tom_tom/errors.rb new file mode 100644 index 000000000..da3f2239c --- /dev/null +++ b/lib/tom_tom/errors.rb @@ -0,0 +1,4 @@ +module TomTom +  module Errors +  end +end diff --git a/lib/tom_tom/errors/matrix_remote_error.rb b/lib/tom_tom/errors/matrix_remote_error.rb new file mode 100644 index 000000000..b13767847 --- /dev/null +++ b/lib/tom_tom/errors/matrix_remote_error.rb @@ -0,0 +1,5 @@ +module TomTom +  module Errors +    class MatrixRemoteError < RuntimeError; end +  end +end diff --git a/lib/tom_tom/matrix.rb b/lib/tom_tom/matrix.rb index d0b476d84..96518f7cf 100644 --- a/lib/tom_tom/matrix.rb +++ b/lib/tom_tom/matrix.rb @@ -6,8 +6,8 @@ module TomTom      # Exceptions:      # -    # * This raises a `TomTom::Matrix::RemoteError` when the API responds with -    #   an error. +    # * 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) @@ -84,13 +84,14 @@ module TomTom      def check_for_error_response(response)        if response.status != 200 -        raise RemoteError, "status: #{response.status}, body: #{response.body}" +        raise TomTom::Errors::MatrixRemoteError, +          "status: #{response.status}, body: #{response.body}"        end        json = JSON.parse(response.body)        if json.has_key?('error') -        raise RemoteError, +        raise TomTom::Errors::MatrixRemoteError,            "status: #{response.status}, message: #{json['error']['description']}"        end      end diff --git a/lib/tom_tom/matrix/remote_error.rb b/lib/tom_tom/matrix/remote_error.rb deleted file mode 100644 index a5a7b3cdb..000000000 --- a/lib/tom_tom/matrix/remote_error.rb +++ /dev/null @@ -1,5 +0,0 @@ -module TomTom -  class Matrix -    class RemoteError < RuntimeError; end -  end -end diff --git a/spec/lib/tom_tom/matrix_spec.rb b/spec/lib/tom_tom/matrix_spec.rb index 6564b82fd..f914cf7ff 100644 --- a/spec/lib/tom_tom/matrix_spec.rb +++ b/spec/lib/tom_tom/matrix_spec.rb @@ -150,7 +150,7 @@ RSpec.describe TomTom::Matrix do    end    describe "#check_for_error_response" do -    it "raises a RemoteError when an 'error' key is present in the response" do +    it "raises a MatrixRemoteError when an 'error' key is present in the response" do        response = double(          'response',          status: 200, @@ -165,12 +165,12 @@ RSpec.describe TomTom::Matrix do        expect {          matrix.check_for_error_response(response)        }.to raise_error( -        TomTom::Matrix::RemoteError, +        TomTom::Errors::MatrixRemoteError,          "status: #{response.status}, message: Output format: csv is unsupported."        )      end -    it "raises a RemoteError when response status is not 200" do +    it "raises a MatrixRemoteError when response status is not 200" do        response = double(          'response',          status: 403, @@ -180,7 +180,7 @@ RSpec.describe TomTom::Matrix do        expect {          matrix.check_for_error_response(response)        }.to raise_error( -        TomTom::Matrix::RemoteError, +        TomTom::Errors::MatrixRemoteError,          "status: #{response.status}, body: <h1>Developer Inactive</h1>"        )      end | 
