I have a code block like this:
try:
gitlab.gl_delete_project(gitlab_project_id)
except DevOpsError as e:
if e.status_code != 404:
raise e
try:
redmine.rm_delete_project(redmine_project_id)
except DevOpsError as e:
if e.status_code != 404:
raise e
try:
if harbor_project_id is not None:
harbor.hb_delete_project(harbor_project_id)
except DevOpsError as e:
if e.status_code != 404:
raise e
Each method may raise a DevOpsError
, and in some conditions, I just want to ignore the Exception, or re-raise it in other times.
Since the try/except block are all identical, is there a way to simplify the code?
Edit: I'm suggested a similar question, but it does not tell me how to pass arguments to the methods.