Skip to content

Commit

Permalink
Issue #332: Hide traceback from UnprocessableEntity error (#336)
Browse files Browse the repository at this point in the history
* hide UnprocessableEntityError traceback from user

* extract message from HTTPError

* remove suggestion to open issue when 422 is responsed
  • Loading branch information
rifel123 authored Nov 9, 2021
1 parent cbb5316 commit 1f61bd0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions git_machete/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def __init__(self) -> None:
pass


class UnprocessableEntityHTTPError(Exception):
class UnprocessableEntityHTTPError(MacheteException):
"""This exception is raised when Github API returns HTTP status code 422 - Unprocessable Entity.
Such a situation occurs when trying to do something not allowed by GitHub,
e.g. assigning someone from outside organization as a reviewer
or creating a pull request for a branch that already has a PR.
"""
def __init__(self, msg: str) -> None:
self.msg: str = msg + "\nPlease open an issue regarding this topic under link: https://github.com/VirtusLab/git-machete/issues/new"
self.msg: str = 'UnprocessableEntityHTTPError: ' + msg

def __str__(self) -> str:
return str(self.msg)
4 changes: 3 additions & 1 deletion git_machete/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ def __fire_github_api_request(method: str, path: str, token: Optional[str], requ
return parsed_response_body
except HTTPError as err:
if err.code == http.HTTPStatus.UNPROCESSABLE_ENTITY:
raise UnprocessableEntityHTTPError(str(err.reason))
error_response = json.loads(err.read().decode())
error_reason: str = error_response['errors'][0]['message']
raise UnprocessableEntityHTTPError(error_reason)
elif err.code in (http.HTTPStatus.UNAUTHORIZED, http.HTTPStatus.FORBIDDEN):
first_line = f'GitHub API returned {err.code} HTTP status with error message: `{err.reason}`\n'
if token:
Expand Down

0 comments on commit 1f61bd0

Please sign in to comment.