Skip to content
Snippets Groups Projects
Verified Commit fab9c75e authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

api: Improve handling of broken 200 responses

parent c5552d6c
Branches
Tags
No related merge requests found
......@@ -2,6 +2,7 @@
- Adds separate state event handler as Client#on_state_event
- Fixes state events being sent twice if included in both timeline and state of a sync
- Improves error reporting of broken 200 responses
- Improves event handlers for rooms, to not depend on a specific room object instance anymore
## 2.1.2 - 2020-09-10
......
......@@ -304,7 +304,11 @@ module MatrixSdk
end
print_http(response, duration: duration, id: req_id)
data = JSON.parse(response.body, symbolize_names: true) rescue nil
begin
data = JSON.parse(response.body, symbolize_names: true)
rescue
data = nil
end
if response.is_a? Net::HTTPTooManyRequests
raise MatrixRequestError.new_by_code(data, response.code) unless autoretry
......@@ -315,7 +319,13 @@ module MatrixSdk
next
end
return MatrixSdk::Response.new self, data if response.is_a? Net::HTTPSuccess
if response.is_a? Net::HTTPSuccess
unless data
logger.error "Received non-parsable data in 200 response; #{response.body.inspect}"
raise MatrixConnectionError, response
end
return MatrixSdk::Response.new self, data
end
raise MatrixRequestError.new_by_code(data, response.code) if data
raise MatrixConnectionError.class_by_code(response.code), response
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment