Skip to content

Commit 55f5c2f

Browse files
committed
add more error parse types
1 parent 8b4298c commit 55f5c2f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/lunchmoney/api_call.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ def request(json_request: false, flat_params: false)
6161
def errors(response)
6262
body = response.body
6363

64-
return parse_errors(body) if body.is_a?(Hash) && body[:error]
64+
return parse_errors(body) unless error_hash(body).nil?
6565

6666
[]
6767
end
6868

6969
sig { params(body: T::Hash[Symbol, T.any(String, T::Array[String])]).returns(LunchMoney::Errors) }
7070
def parse_errors(body)
71-
errors = body[:error] || body[:errors]
71+
errors = error_hash(body)
7272
return [] if errors.blank?
7373

7474
api_errors = []
@@ -84,5 +84,18 @@ def parse_errors(body)
8484

8585
api_errors
8686
end
87+
88+
sig { params(body: T.untyped).returns(T.untyped) }
89+
def error_hash(body)
90+
return unless body.is_a?(Hash)
91+
92+
if body[:error]
93+
body[:error]
94+
elsif body[:errors]
95+
body[:errors]
96+
elsif body[:name] == "Error"
97+
body[:message]
98+
end
99+
end
87100
end
88101
end

0 commit comments

Comments
 (0)