Skip to content

Commit 6da3958

Browse files
committed
Fix error message parsing in ErrorHandler
ErrorHandler now parses JSON response body before passing to RequestError.from_response, ensuring error messages are extracted correctly (e.g., 'Bad Request' instead of '{"detail":"Bad Request"}')
1 parent a3f3be9 commit 6da3958

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/uploadcare/error_handler.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ def handle_error(error)
88
response = error.response
99
catch_upload_errors(response)
1010

11+
# Parse JSON body if it's a string
12+
parsed_response = response.dup
13+
if response[:body].is_a?(String) && !response[:body].empty?
14+
begin
15+
parsed_response[:body] = JSON.parse(response[:body])
16+
rescue JSON::ParserError
17+
# Keep original body if JSON parsing fails
18+
end
19+
end
20+
1121
# Use RequestError.from_response to create the appropriate error type
12-
raise Uploadcare::RequestError.from_response(response)
22+
raise Uploadcare::RequestError.from_response(parsed_response)
1323
end
1424

1525
private

0 commit comments

Comments
 (0)