File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed
Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,25 @@ class ParamsError < ClientError; end
66 class InvalidAuthKeyError < ClientError ; end
77 class BlockMissingError < ParamsError ; end
88 class ServerError < Exception ; end # Error reported back by Binfinex server
9+ class BadRequestError < ServerError ; end
10+ class NotFoundError < ServerError ; end
11+ class ForbiddenError < ServerError ; end
12+ class UnauthorizedError < ServerError ; end
13+ class InternalServerError < ServerError ; end
914
1015 class CustomErrors < Faraday ::Response ::Middleware
1116 def on_complete ( env )
1217 case env [ :status ]
13- when 400 ..500
14- raise ServerError , env . body [ 'message' ]
18+ when 400
19+ raise BadRequestError , env . body [ 'message' ]
20+ when 401
21+ raise UnauthorizedError
22+ when 403
23+ raise ForbiddenError
24+ when 404
25+ raise NotFoundError
26+ when 500
27+ raise InternalServerError
1528 else
1629 super
1730 end
Original file line number Diff line number Diff line change 11module Bitfinex
2- VERSION = "0.0.5 "
2+ VERSION = "0.0.6 "
33end
Original file line number Diff line number Diff line change 1616 stub_http ( "/pubticker/btcusd" , { message : "error message 400" } . to_json , status : 400 )
1717 end
1818
19- it { expect { client . ticker } . to raise_error ( Bitfinex ::ServerError ) }
19+ it { expect { client . ticker } . to raise_error ( Bitfinex ::BadRequestError , "error message 400" ) }
20+ end
21+
22+ context "401 error" do
23+ before do
24+ stub_http ( "/pubticker/btcusd" , { message : "unauthorized 401" } . to_json , status : 401 )
25+ end
26+
27+ it { expect { client . ticker } . to raise_error ( Bitfinex ::UnauthorizedError ) }
28+ end
29+
30+ context "403 error" do
31+ before do
32+ stub_http ( "/pubticker/btcusd" , { message : "forbidden 403" } . to_json , status : 403 )
33+ end
34+
35+ it { expect { client . ticker } . to raise_error ( Bitfinex ::ForbiddenError ) }
36+ end
37+
38+ context "404 error" do
39+ before do
40+ stub_http ( "/pubticker/btcusd" , { message : "404 not found" } . to_json , status :404 )
41+ end
42+
43+ it { expect { client . ticker } . to raise_error ( Bitfinex ::NotFoundError ) }
2044 end
2145
2246
2549 stub_http ( "/pubticker/btcusd" , { message : "error message 500" } . to_json , status :500 )
2650 end
2751
28- it { expect { client . ticker } . to raise_error ( Bitfinex ::ServerError , "error message 500" ) }
52+ it { expect { client . ticker } . to raise_error ( Bitfinex ::InternalServerError ) }
2953 end
3054
3155end
You can’t perform that action at this time.
0 commit comments