Sha256: f36f1d3d515cd701b632caf00dd8fedc9dd45257c45584a5c5648179cf4e4c82
Contents?: true
Size: 1.85 KB
Versions: 2
Compression:
Stored size: 1.85 KB
Contents
# frozen_string_literal: true require 'json' module Fintecture class ValidationException < RuntimeError; end class CryptoException < RuntimeError; end class ApiException class << self def error(res) body = JSON.parse res.body # Errors array if body['code'] && body['log_id'] && body['errors'] raise _construct_message_errors(res, body) # Single error else raise _construct_message_error(res, body) end end private def _construct_message_errors(res, body) status = res.status code = body['code'] log_id = body['log_id'] errors_array = body['errors'] error_string = "\nFintecture server errors : " error_string += "\n status: #{status} " error_string += "\n code: #{code}" error_string += "\n id : #{log_id}" errors_array.each do |error| formated_error = error.map { |key, value| " #{key}: #{value}" }.join("\n") error_string += "\n\n#{formated_error}" end error_string += "\n\n" { type: 'Fintecture api', status: status, errors: errors_array, error_string: error_string }.to_json end def _construct_message_error(res, body) status = res.status error = body['meta'] error_string = "\nFintecture server errors : " error_string += "\n status: #{status} " formated_error = error.map { |key, value| " #{key}: #{value}" }.join("\n") error_string += "\n\n#{formated_error}" error_string += "\n\n" { type: 'Fintecture api', status: status, errors: [error], error_string: error_string }.to_json end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fintecture-0.3.1 | lib/fintecture/exceptions.rb |
fintecture-0.3.0 | lib/fintecture/exceptions.rb |