Skip to content

Exception Handling ## Business Purpose

Provide a comprehensive set of exception classes that map HTTP and network errors to specific, catchable exceptions, enabling robust error handling in applications. ## Current Behaviors - RequestException is the base class inheriting from IOError and captures response and request attributes src/requests/exceptions.py:20. - Subclasses include HTTPError, ConnectionError, ProxyError, SSLError, Timeout, ConnectTimeout, ReadTimeout, URLRequired, TooManyRedirects, MissingSchema, InvalidSchema, InvalidURL, InvalidHeader, InvalidProxyURL, ChunkedEncodingError, ContentDecodingError, StreamConsumedError, RetryError, UnrewindableBodyError src/requests/exceptions.py:20. - JSONDecodeError is a combined exception inheriting from both InvalidJSONError and the compatible JSONDecodeError from json module src/requests/exceptions.py:38. - Warning classes RequestsWarning, FileModeWarning, RequestsDependencyWarning src/requests/exceptions.py:153. ## Technical Implementation Internal urllib3 exceptions are caught in HTTPAdapter.send() and re-raised as Requests exceptions src/requests/adapters.py:634. The JSONDecodeError is raised in Response.json() when JSON parsing fails src/requests/models.py:1031. ## Definition of Done - An HTTP 404 response raises HTTPError when raise_for_status() is called. - A connection timeout raises ConnectTimeout (subclass of ConnectionError and Timeout). - A malformed URL raises InvalidURL. - Invalid header values raise InvalidHeader. - requests.exceptions.JSONDecodeError is catchable as both InvalidJSONError and json.JSONDecodeError.