Commit 2037936f authored by sergio1990's avatar sergio1990

Merge branch 'api-ng-exception'

parents bb388430 266e8618
......@@ -51,6 +51,10 @@ Please check [wiki pages](https://github.com/alterego-labs/betfair_api_ng_rails/
4. Added shortcuts for models
5. Refactoring
## Specs
You may running all specs by `rspec spec --color` to be sure that all is alright.
## Contributing
1. Fork it
......
require "rubygems"
require 'rspec/core/rake_task'
require 'rubygems/specification'
# require 'rspec/core/rake_task'
# require 'rubygems/specification'
task default: :spec
desc "Run specs"
RSpec::Core::RakeTask.new do |t|
t.pattern = FileList['spec/**/*_spec.rb']
t.rspec_opts = %w(--color)
end
# task default: :spec
# desc "Run specs"
# RSpec::Core::RakeTask.new do |t|
# t.pattern = FileList['spec/**/*_spec.rb']
# t.rspec_opts = %w(--color)
# end
......@@ -122,8 +122,9 @@ module BetfairApiNgRails
module ConnectionExt
autoload :Parsing, 'betfair_api_ng_rails/api/connection_ext/parsing'
autoload :Formatting, 'betfair_api_ng_rails/api/connection_ext/formatting'
autoload :ErrorHandling, 'betfair_api_ng_rails/api/connection_ext/error_handling'
autoload :Parsing, 'betfair_api_ng_rails/api/connection_ext/parsing'
autoload :Formatting, 'betfair_api_ng_rails/api/connection_ext/formatting'
end
......
require "betfair_api_ng_rails/errors"
module BetfairApiNgRails
module Api
class Connection
......@@ -12,6 +14,7 @@ module BetfairApiNgRails
provider.fetch method: method, params: hashing(params)
end
include Api::ConnectionExt::ErrorHandling
include Api::ConnectionExt::Parsing
include Api::ConnectionExt::Formatting
......
require 'active_support/inflector'
require "betfair_api_ng_rails/errors"
module BetfairApiNgRails
module Api
module ConnectionExt
module ErrorHandling
include BetfairApiNgRails::Api::Constants
def self.included(base)
base.send :class_eval, <<-CODE
def request_with_error_handling(method, params = {})
res = request_without_error_handling(method, params)
raise_exception(res.error_info) if res.has_error?
res
end
alias_method :request_without_error_handling, :request
alias_method :request, :request_with_error_handling
CODE
end
private
def raise_exception(error)
raise BetfairApiNgRails::APINGException.new(error), "Error in #{error[:type]} section"
end
end
end
end
end
\ No newline at end of file
......@@ -3,4 +3,11 @@ module BetfairApiNgRails
class NoConnectionError < ::StandardError
end
class APINGException < ::StandardError
attr_reader :info
def initialize(info)
@info = info
end
end
end
\ No newline at end of file
......@@ -17,6 +17,7 @@ describe BetfairApiNgRails::Api::Connection do
let(:provider) { double(:provider) }
let(:parser) { double(:parser, process: true) }
let(:response) { double(:response) }
before(:each) do
expect_any_instance_of(described_class).to receive(:request_ssoid)
......@@ -25,7 +26,8 @@ describe BetfairApiNgRails::Api::Connection do
it "calls provider's fetch method" do
expect(subject).to receive(:provider).and_return provider
expect(provider).to receive(:fetch).with(method: 'method', params: {})
expect(provider).to receive(:fetch).with(method: 'method', params: {}).and_return response
expect(response).to receive(:has_error?).and_return false
expect(subject).to receive(:hashing).with({}).and_return({})
subject.request 'method'
end
......
......@@ -22,7 +22,9 @@ shared_examples 'simple list filtering request' do |method|
let(:result_hash) { "{\"error\":{\"code\":-32700,\"message\":\"DSC-3000\"}}" }
it { is_expected.to be_empty }
it "raise APINGException" do
expect{ subject }.to raise_error
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment