@@ -58,7 +58,8 @@ defmodule Sentry.Transport do
5858 end
5959
6060 defp request ( client , endpoint , headers , body ) do
61- with { :ok , 200 , _headers , body } <- client . post ( endpoint , headers , body ) ,
61+ with { :ok , 200 , _headers , body } <-
62+ client_post_and_validate_return_value ( client , endpoint , headers , body ) ,
6263 { :ok , json } <- Config . json_library ( ) . decode ( body ) do
6364 { :ok , Map . get ( json , "id" ) }
6465 else
@@ -86,6 +87,21 @@ defmodule Sentry.Transport do
8687 kind , data -> { :error , { kind , data , __STACKTRACE__ } }
8788 end
8889
90+ defp client_post_and_validate_return_value ( client , endpoint , headers , body ) do
91+ case client . post ( endpoint , headers , body ) do
92+ { :ok , status , resp_headers , resp_body }
93+ when is_integer ( status ) and status in 200 .. 599 and is_list ( resp_headers ) and
94+ is_binary ( resp_body ) ->
95+ { :ok , status , resp_headers , resp_body }
96+
97+ { :ok , status , resp_headers , resp_body } ->
98+ { :error , { :malformed_http_client_response , status , resp_headers , resp_body } }
99+
100+ { :error , reason } ->
101+ { :error , reason }
102+ end
103+ end
104+
89105 defp get_endpoint_and_headers do
90106 % Sentry.DSN { } = dsn = Config . dsn ( )
91107
0 commit comments