* CookieConflict
* StreamError
x StreamConsumed
+ x StreamClosed
x ResponseNotRead
x RequestNotRead
- x ResponseClosed
"""
import contextlib
import typing
# the request/response stream in an invalid manner.
-class StreamError(Exception):
+class StreamError(RuntimeError):
"""
The base class for stream exceptions.
super().__init__(message)
-class ResponseNotRead(StreamError):
+class StreamClosed(StreamError):
"""
- Attempted to access streaming response content, without having called `read()`.
+ Attempted to read or stream response content, but the request has been
+ closed.
"""
def __init__(self) -> None:
- message = "Attempted to access streaming response content, without having called `read()`."
+ message = (
+ "Attempted to read or stream content, but the stream has " "been closed."
+ )
super().__init__(message)
-class RequestNotRead(StreamError):
+class ResponseNotRead(StreamError):
"""
- Attempted to access streaming request content, without having called `read()`.
+ Attempted to access streaming response content, without having called `read()`.
"""
def __init__(self) -> None:
- message = "Attempted to access streaming request content, without having called `read()`."
+ message = "Attempted to access streaming response content, without having called `read()`."
super().__init__(message)
-class ResponseClosed(StreamError):
+class RequestNotRead(StreamError):
"""
- Attempted to read or stream response content, but the request has been
- closed.
+ Attempted to access streaming request content, without having called `read()`.
"""
def __init__(self) -> None:
- message = (
- "Attempted to read or stream response content, but the request has "
- "been closed."
- )
+ message = "Attempted to access streaming request content, without having called `read()`."
super().__init__(message)
HTTPStatusError,
InvalidURL,
RequestNotRead,
- ResponseClosed,
ResponseNotRead,
+ StreamClosed,
StreamConsumed,
request_context,
)
if self.is_stream_consumed:
raise StreamConsumed()
if self.is_closed:
- raise ResponseClosed()
+ raise StreamClosed()
if not isinstance(self.stream, SyncByteStream):
raise RuntimeError("Attempted to call a sync iterator on an async stream.")
if self.is_stream_consumed:
raise StreamConsumed()
if self.is_closed:
- raise ResponseClosed()
+ raise StreamClosed()
if not isinstance(self.stream, AsyncByteStream):
raise RuntimeError("Attempted to call an async iterator on an sync stream.")