Exception: Integrobr::NfseSdk::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/integrobr/nfse_sdk/errors.rb

Overview

Erro devolvido pela API pública do IntegroBR — sempre no formato { statusCode, message, error }, onde message pode ser uma string única ou uma lista (um item por campo inválido, em erros 400).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, mensagem, erro_tipo = nil) ⇒ ApiError

Returns a new instance of ApiError.



11
12
13
14
15
16
# File 'lib/integrobr/nfse_sdk/errors.rb', line 11

def initialize(status_code, mensagem, erro_tipo = nil)
  @status_code = status_code
  @mensagens = mensagem.is_a?(Array) ? mensagem : [mensagem]
  @erro_tipo = erro_tipo
  super(@mensagens.join(" "))
end

Instance Attribute Details

#erro_tipoObject (readonly)

Returns the value of attribute erro_tipo.



9
10
11
# File 'lib/integrobr/nfse_sdk/errors.rb', line 9

def erro_tipo
  @erro_tipo
end

#mensagensObject (readonly)

Returns the value of attribute mensagens.



9
10
11
# File 'lib/integrobr/nfse_sdk/errors.rb', line 9

def mensagens
  @mensagens
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



9
10
11
# File 'lib/integrobr/nfse_sdk/errors.rb', line 9

def status_code
  @status_code
end

Instance Method Details

#nao_autenticado?Boolean

401 — chave ausente, inválida ou revogada.

Returns:

  • (Boolean)


24
25
26
# File 'lib/integrobr/nfse_sdk/errors.rb', line 24

def nao_autenticado?
  status_code == 401
end

#nao_encontrado?Boolean

404 — cobre tanto "não existe" quanto "existe, mas no outro ambiente (sandbox/produção)" da mesma conta.

Returns:

  • (Boolean)


30
31
32
# File 'lib/integrobr/nfse_sdk/errors.rb', line 30

def nao_encontrado?
  status_code == 404
end

#rate_limited?Boolean

429 — limite de 120 requisições/minuto por chave excedido.

Returns:

  • (Boolean)


19
20
21
# File 'lib/integrobr/nfse_sdk/errors.rb', line 19

def rate_limited?
  status_code == 429
end