Skip to content

Commit d60ae58

Browse files
committed
feat: Get error status phrase from status code
BREAKING CHANGE: HTTPStatus is new in Python3
1 parent b1177f2 commit d60ae58

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

ibm_cloud_sdk_core/api_exception.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
from typing import Optional
17+
from http import HTTPStatus
1718
from requests import Response
1819

1920

@@ -66,6 +67,8 @@ def _get_error_message(response: Response):
6667
error_message = error_json['errorMessage']
6768
elif response.status_code == 401:
6869
error_message = 'Unauthorized: Access is denied due to invalid credentials'
70+
else:
71+
error_message = HTTPStatus(response.status_code).phrase
6972
return error_message
7073
except:
7174
return response.text or error_message

test/test_api_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_api_exception():
4848
content_type='application/json')
4949
mock_response = requests.get('https://test-msg.com')
5050
exception = ApiException(500, http_response=mock_response)
51-
assert exception.message == 'Unknown error'
51+
assert exception.message == 'Internal Server Error'
5252

5353
responses.add(responses.GET,
5454
'https://test-errormessage.com',

0 commit comments

Comments
 (0)