From 723c7c936c2f10f5064894836cc960cf58094c9b Mon Sep 17 00:00:00 2001 From: Gal Topper Date: Sun, 31 Mar 2024 20:52:01 +0800 Subject: [PATCH] Improve error message in case of a redirect (#119) --- v3io/dataplane/response.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/v3io/dataplane/response.py b/v3io/dataplane/response.py index f162ae7..3bf0705 100644 --- a/v3io/dataplane/response.py +++ b/v3io/dataplane/response.py @@ -73,9 +73,14 @@ def raise_for_status(self, expected_statuses=None): if (expected_statuses is None and self.status_code >= 300) or ( expected_statuses and self.status_code not in expected_statuses ): - raise HttpResponseError( - "Request failed with status {0}: {1}".format(self.status_code, self.body), status_code=self.status_code - ) + if 308 <= self.status_code < 400: + location = self.headers.get("Location") + error_message = "Request failed due to a Permanent Redirect." + if location: + error_message += f" Please change URL to: {location}" + else: + error_message = f"Request failed with status {self.status_code}: {self.body}" + raise HttpResponseError(error_message, status_code=self.status_code) class Responses(object):