Exception: Epayco::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Epayco::Error
- Includes:
- Enumerable
- Defined in:
- lib/epayco.rb
Overview
Set custom error
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(code, lang) ⇒ Error
constructor
Get code, lang and show custom error.
Constructor Details
#initialize(code, lang) ⇒ Error
Get code, lang and show custom error
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/epayco.rb', line 18 def initialize(code, lang) begin file = open("https://multimedia.epayco.co/message-api/errors.json").read data_hash = JSON.parse(file) rescue OpenURI::HTTPError, Errno::ENOENT => e # Si no se puede acceder al archivo remoto, usar un archivo local como respaldo local_file_path = File.join(File.dirname(__FILE__), 'errors.json') if File.exist?(local_file_path) file = File.read(local_file_path) data_hash = JSON.parse(file) else raise "No se pudo cargar el archivo de errores: #{e.}" end end error = "Error" if(data_hash[code.to_s]) error = [data_hash[code.to_s][lang]] else error = [code, lang] end super error @errors = error end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
15 16 17 |
# File 'lib/epayco.rb', line 15 def errors @errors end |
Instance Method Details
#each ⇒ Object
43 44 45 |
# File 'lib/epayco.rb', line 43 def each @errors.each { |e| yield *e } end |