From 2a2656c5dd5df5cd66e2be7f86291ac6533d731b Mon Sep 17 00:00:00 2001 From: VarMonke Date: Mon, 4 Apr 2022 21:55:08 +0530 Subject: [PATCH] exceptions --- Github/exceptions.py | 6 ++++++ Github/http.py | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Github/exceptions.py b/Github/exceptions.py index bf419db..94b45af 100644 --- a/Github/exceptions.py +++ b/Github/exceptions.py @@ -87,4 +87,10 @@ class NotStarted(APIError): """Raised when a call is made before start is called.""" def __init__(self): msg = 'You must call `await .start()` before making this call.' + super().__init__(msg) + +class RepositoryAlreadyExists(APIError): + """Raised when a repository already exists.""" + def __init__(self): + msg = 'The repository you are trying to create already exists.' super().__init__(msg) \ No newline at end of file diff --git a/Github/http.py b/Github/http.py index eee6666..2b5a100 100644 --- a/Github/http.py +++ b/Github/http.py @@ -8,6 +8,7 @@ import re import json from .exceptions import * +from .exceptions import RepositoryAlreadyExists from .objects import * from .urls import * @@ -144,12 +145,14 @@ async def get_repo_issue(session: aiohttp.ClientSession, owner: str, repo_name: async def make_repo(session: aiohttp.ClientSession, name: str) -> Repository: """Creates a new repo with the given name.""" _data = {"name" : name} - try: - result = await session.post(MAKE_REPO_URL, data= json.dumps(_data)) - if result.status == 201: - return Repository(await result.json(), session) - except Exception: - print(Exception) + result = await session.post(MAKE_REPO_URL, data= json.dumps(_data)) + if result.status == 201: + return Repository(await result.json(), session) + if result.status == 401: + raise NoAuthProvided + raise RepositoryAlreadyExists + + # org-related functions / utils