1
Fork 0
mirror of https://github.com/RGBCube/GitHubWrapper synced 2025-05-18 23:15:09 +00:00

exceptions

This commit is contained in:
VarMonke 2022-04-04 21:55:08 +05:30
parent 36c9c6eb6d
commit 2a2656c5dd
2 changed files with 15 additions and 6 deletions

View file

@ -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 <Github_instance>.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)

View file

@ -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