Skip to content

Commit fffd37e

Browse files
committed
fix: solve error handler 4 pix
1 parent 1f8f4c9 commit fffd37e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

app/controllers/api/v1/wallet_controller.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,26 @@ def proxy_to_propay(method, path, body: nil, idempotency_key: nil)
119119
http_request = build_http_request(method, uri, body, idempotency_key)
120120

121121
response = http.request(http_request)
122-
render json: JSON.parse(response.body), status: response.code.to_i
122+
parsed = parse_propay_body(response.body)
123+
render json: parsed, status: response.code.to_i
123124
rescue Net::OpenTimeout, Net::ReadTimeout
124125
render json: { error: { message: 'ProPay timeout' } }, status: :gateway_timeout
125126
rescue StandardError => e
126127
Rails.logger.error("[WALLET] ProPay proxy error for #{path}: #{e.message}")
127128
render json: { error: { message: e.message } }, status: :bad_gateway
128129
end
129130

131+
# Parses a ProPay response body, returning a fallback hash on invalid JSON.
132+
#
133+
# @param body [String] Raw response body
134+
# @return [Hash]
135+
def parse_propay_body(body)
136+
JSON.parse(body)
137+
rescue JSON::ParserError
138+
Rails.logger.error("[WALLET] ProPay returned non-JSON body: #{body.to_s.truncate(200)}")
139+
{ 'error' => 'ProPay returned an invalid response' }
140+
end
141+
130142
# Builds a configured Net::HTTP instance.
131143
#
132144
# @param uri [URI] Target URI

0 commit comments

Comments
 (0)