Skip to content

Commit

Permalink
feat: Get error status phrase from status code
Browse files Browse the repository at this point in the history
BREAKING CHANGE: HTTPStatus is new in Python3
  • Loading branch information
rmkeezer committed Apr 10, 2020
1 parent b1177f2 commit d60ae58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ibm_cloud_sdk_core/api_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional
from http import HTTPStatus
from requests import Response


Expand Down Expand Up @@ -66,6 +67,8 @@ def _get_error_message(response: Response):
error_message = error_json['errorMessage']
elif response.status_code == 401:
error_message = 'Unauthorized: Access is denied due to invalid credentials'
else:
error_message = HTTPStatus(response.status_code).phrase
return error_message
except:
return response.text or error_message
2 changes: 1 addition & 1 deletion test/test_api_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_api_exception():
content_type='application/json')
mock_response = requests.get('https://test-msg.com')
exception = ApiException(500, http_response=mock_response)
assert exception.message == 'Unknown error'
assert exception.message == 'Internal Server Error'

responses.add(responses.GET,
'https://test-errormessage.com',
Expand Down

0 comments on commit d60ae58

Please sign in to comment.