Class: BWStatusBoardAPI::Response::Error

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/bw_status_board_api/response/error.rb

Overview

Brandwatch Status Board API response middleware to handle errors

Constant Summary collapse

ERROR_MAP =
{
  400 => BWStatusBoardAPI::BadRequest,
  401 => BWStatusBoardAPI::Unauthorized,
  403 => BWStatusBoardAPI::Forbidden,
  404 => BWStatusBoardAPI::NotFound,
  406 => BWStatusBoardAPI::NotAcceptable,
  422 => BWStatusBoardAPI::UnprocessableEntity,
  429 => BWStatusBoardAPI::TooManyRequests,
  500 => BWStatusBoardAPI::InternalServerError,
  501 => BWStatusBoardAPI::NotImplemented,
  502 => BWStatusBoardAPI::BadGateway,
  503 => BWStatusBoardAPI::ServiceUnavailable
}

Instance Method Summary collapse

Instance Method Details

#on_complete(response) ⇒ Object



22
23
24
25
# File 'lib/bw_status_board_api/response/error.rb', line 22

def on_complete(response)
  key = response[:status].to_i
  fail ERROR_MAP[key].new(response) if ERROR_MAP.key? key
end