Module: FocusNfe::Errors
- Defined in:
- lib/focus_nfe/errors.rb
Overview
Exceções tipadas: falhas HTTP (por faixa de status), de configuração
(client-side) e de conexão (transporte). Reúne também o mapeamento
status → classe e a construção da exceção a partir de uma Response.
Defined Under Namespace
Classes: BadRequest, ConfigurationError, Conflict, ConnectionError, Forbidden, HttpError, NotFound, RateLimited, ServerError, Unauthorized, UnexpectedResponse, ValidationError, WebhookError
Constant Summary collapse
- BY_STATUS =
Returns status HTTP específico => classe de exceção.
{ 400 => BadRequest, 401 => Unauthorized, 403 => Forbidden, 404 => NotFound, 409 => Conflict, 422 => ValidationError, 429 => RateLimited }.freeze
Class Method Summary collapse
-
.class_for(status) ⇒ Class
Resolve a classe de exceção correspondente a um status HTTP.
-
.from_response(response) ⇒ HttpError
Constrói a exceção tipada já preenchida a partir de uma resposta.
Class Method Details
.class_for(status) ⇒ Class
Resolve a classe de exceção correspondente a um status HTTP.
106 107 108 |
# File 'lib/focus_nfe/errors.rb', line 106 def class_for(status) BY_STATUS[status] || (status.between?(500, 599) ? ServerError : UnexpectedResponse) end |
.from_response(response) ⇒ HttpError
Constrói a exceção tipada já preenchida a partir de uma resposta.
114 115 116 117 118 119 120 121 |
# File 'lib/focus_nfe/errors.rb', line 114 def from_response(response) class_for(response.status).new( "requisição falhou com status #{response.status}", status: response.status, body: response.body, response: response ) end |