Module: Barzahlen::Error
- Defined in:
- lib/barzahlen/error.rb
Defined Under Namespace
Classes: ApiError, AuthError, ClientError, IdempotencyError, InvalidFormatError, InvalidParameterError, InvalidStateError, NotAllowedError, RateLimitError, ServerError, SignatureError, TransportError, UnexpectedError
Class Method Summary
collapse
Class Method Details
.generate_error_from_response(response_body) ⇒ Object
This generates ApiErrors based on the response error classes of CPS
.generate_error_hash_with_symbols(body) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/barzahlen/error.rb', line 94
def self.generate_error_hash_with_symbols(body)
if body.is_a?(Hash)
error_hash = self.symbolize_keys(body)
elsif body.is_a?(String)
error_hash = parse_json(body) || {}
else
error_hash = Hash.new
end
error_hash[:error_class] ||= "Unexpected_Error"
error_hash[:error_code] ||= "Unknown error code (body): \"#{body.to_s}\""
error_hash[:message] ||= "Please contact viafintech to help us fix that as soon as possible."
error_hash[:documentation_url] ||= "https://www.viafintech.com/contact/"
error_hash[:request_id] ||= "not_available"
error_hash
end
|
.parse_json(json) ⇒ Object
85
86
87
88
89
90
91
92
|
# File 'lib/barzahlen/error.rb', line 85
def self.parse_json(json)
begin
hash = JSON.parse(json)
rescue JSON::ParserError => e
return nil
end
self.symbolize_keys(hash)
end
|
.symbolize_keys(hash) ⇒ Object
112
113
114
|
# File 'lib/barzahlen/error.rb', line 112
def self.symbolize_keys(hash)
Hash[hash.map{ |k, v| [k.to_sym, v] }]
end
|