Exception: WeChat::Error
- Inherits:
-
StandardError
- Object
- StandardError
- WeChat::Error
- Defined in:
- lib/we_chat/error.rb
Overview
Custom error class for rescuing from all WeChat errors
Constant Summary collapse
- ClientError =
Raised when WeChat returns a 4xx HTTP status code
Class.new(self)
- BadRequest =
Raised when WeChat returns the HTTP status code 400
Class.new(ClientError)
Class.new(ClientError)
- Forbidden =
Raised when WeChat returns the HTTP status code 403
Class.new(ClientError)
- AlreadyFavorited =
Raised when a Tweet has already been favorited
Class.new(Forbidden)
- AlreadyRetweeted =
Raised when a Tweet has already been retweeted
Class.new(Forbidden)
- DuplicateStatus =
Raised when a Tweet has already been posted
Class.new(Forbidden)
- NotFound =
Raised when WeChat returns the HTTP status code 404
Class.new(ClientError)
- NotAcceptable =
Raised when WeChat returns the HTTP status code 406
Class.new(ClientError)
- UnprocessableEntity =
Raised when WeChat returns the HTTP status code 422
Class.new(ClientError)
- TooManyRequests =
Raised when WeChat returns the HTTP status code 429
Class.new(ClientError)
- ServerError =
Raised when WeChat returns a 5xx HTTP status code
Class.new(self)
- InternalServerError =
Raised when WeChat returns the HTTP status code 500
Class.new(ServerError)
- BadGateway =
Raised when WeChat returns the HTTP status code 502
Class.new(ServerError)
Class.new(ServerError)
- GatewayTimeout =
Raised when WeChat returns the HTTP status code 504
Class.new(ServerError)
- ERRORS =
{ 400 => WeChat::Error::BadRequest, 401 => WeChat::Error::Unauthorized, 403 => WeChat::Error::Forbidden, 404 => WeChat::Error::NotFound, 406 => WeChat::Error::NotAcceptable, 422 => WeChat::Error::UnprocessableEntity, 429 => WeChat::Error::TooManyRequests, 500 => WeChat::Error::InternalServerError, 502 => WeChat::Error::BadGateway, 503 => WeChat::Error::ServiceUnavailable, 504 => WeChat::Error::GatewayTimeout, }
Instance Attribute Summary collapse
- #code ⇒ Integer readonly
Class Method Summary collapse
-
.from_response(body, headers) ⇒ WeChat::Error
Create a new error from an HTTP response.
Instance Method Summary collapse
-
#initialize(message = '', headers = {}, code = nil) ⇒ WeChat::Error
constructor
Initializes a new Error object.
Constructor Details
#initialize(message = '', headers = {}, code = nil) ⇒ WeChat::Error
Initializes a new Error object
100 101 102 103 |
# File 'lib/we_chat/error.rb', line 100 def initialize( = '', headers = {}, code = nil) super() @code = code end |
Instance Attribute Details
#code ⇒ Integer (readonly)
5 6 7 |
# File 'lib/we_chat/error.rb', line 5 def code @code end |
Class Method Details
.from_response(body, headers) ⇒ WeChat::Error
Create a new error from an HTTP response
76 77 78 79 |
# File 'lib/we_chat/error.rb', line 76 def from_response(body, headers) , code = parse_error(body) new(, headers, code) end |