Skip to content
Myr

Add `raise_for_status` to `Response`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Matus Ferech · committed by Matus Ferech · parent 8a227c1 · Browse files · 1 file+26 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+26 added−1 removed

  • other:+26 added−1 removed

1 file+26 added−1 removed

modified:httpcore/models.py+26 added-1 removed
12 unmodified lines
13 Decoder,14 IdentityDecoder,15 MultiDecoder,16)17from .exceptions import InvalidURL, ResponseClosed, ResponseNotRead, StreamConsumed17from .exceptions import (18 HttpError,19 InvalidURL,20 ResponseClosed,21 ResponseNotRead,22 StreamConsumed,23)24from .utils import (25 get_reason_phrase,26 is_known_encoding,27 normalize_header_key,
604 unmodified lines
632633 def __repr__(self) -> str:634 class_name = self.__class__.__name__635 return f"<{class_name}(status_code={self.status_code})>"636637 def raise_for_status(self) -> None:638 """639 Raise the `HttpError` if one occurred.640 """641 message = (642 "{0.status_code} {error_type}: {0.reason_phrase} for url: {0.url}\n"643 "For more information check: https://httpstatuses.com/{0.status_code}"644 )645646 if 400 <= self.status_code < 500:647 message = message.format(self, error_type="Client Error")648 elif 500 <= self.status_code < 600:649 message = message.format(self, error_type="Server Error")650 else:651 message = ""652653 if message:654 raise HttpError(message)