Exception: Kuaipan::KpErrors
- Inherits:
-
StandardError
- Object
- StandardError
- Kuaipan::KpErrors
- Defined in:
- lib/kuaipan/errors.rb
Direct Known Subclasses
BadRequest, Forbidden, InnerLogicalError, InternalServerError, NoTypeError, NoViewError, NotAcceptable, NotFound, OverSpace, RequestEntityTooLarge, ServerError, Unauthorized, UnknownError
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ KpErrors
constructor
A new instance of KpErrors.
Constructor Details
#initialize(data) ⇒ KpErrors
Returns a new instance of KpErrors.
4 5 6 7 |
# File 'lib/kuaipan/errors.rb', line 4 def initialize(data) @data = data super end |
Class Method Details
.raise_errors(res) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kuaipan/errors.rb', line 9 def self.raise_errors(res) data = parse(res) case res.code.to_i when 202 raise InnerLogicalError.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" when 400 raise BadRequest.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" when 401 raise Unauthorized.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" when 403 raise Forbidden.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" when 404 raise NotFound.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" when 406 raise NotAcceptable.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" when 413 raise RequestEntityTooLarge.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" when 500 raise InternalServerError.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" when 507 raise OverSpace.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" when 500..505 raise ServerError.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" else raise UnknownError.new(data['msg']), "(#{ res.code }): #{ res. } - #{ data['msg'] }" end end |