@@ -176,6 +176,20 @@ def _handle_error(self, exception: requests.RequestException) -> NoReturn:
176176 if response is None :
177177 raise GeneralError (str (exception )) from exception
178178
179+ self ._raise_for_http_status (response , exception )
180+ # Fallthrough: parse JSON and raise based on error code
181+ try :
182+ data = response .json ()
183+ except JSONDecodeError :
184+ raise ParseError (str (exception )) from exception
185+
186+ self ._raise_for_error_code (data , exception )
187+
188+ def _raise_for_http_status (
189+ self ,
190+ response : requests .Response ,
191+ exception : requests .RequestException ,
192+ ) -> None :
179193 if response .status_code == 429 :
180194 retry_after = response .headers .get ("Retry-After" )
181195 self .retry_after = _parse_retry_after (retry_after )
@@ -200,11 +214,11 @@ def _handle_error(self, exception: requests.RequestException) -> NoReturn:
200214 if response .status_code > 400 :
201215 raise OpenFeatureError (ErrorCode .GENERAL , response .text ) from exception
202216
203- try :
204- data = response . json ()
205- except JSONDecodeError :
206- raise ParseError ( str ( exception )) from exception
207-
217+ def _raise_for_error_code (
218+ self ,
219+ data : dict [ str , Any ],
220+ exception : requests . RequestException ,
221+ ) -> NoReturn :
208222 error_code = ErrorCode (data ["errorCode" ])
209223 error_details = data ["errorDetails" ]
210224
0 commit comments