Skip to content

Commit

Permalink
Merge pull request #3 from aSel1x/main
Browse files Browse the repository at this point in the history
  • Loading branch information
ProFastCode committed Jul 24, 2024
2 parents 7c11081 + e08d213 commit 63da0ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
app.include_router(api.api_router)


@app.exception_handler(exps.BaseException)
async def exception_handler(request, exc: exps.BaseException):
@app.exception_handler(exps.CustomException)
async def exception_handler(request, exc: exps.CustomException):
return JSONResponse(
status_code=exc.status_code,
content={'detail': exc.message},
Expand Down
12 changes: 6 additions & 6 deletions app/core/exps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
"""


class BaseException(Exception):
class CustomException(Exception):
def __init__(self, message: str, status_code: int = 500):
super().__init__(message)
self.message = message
self.status_code = status_code


# Users
class UserExistsException(BaseException):
class UserExistsException(CustomException):
def __init__(self):
super().__init__('User is already taken.', status_code=409)


class UserNotFoundException(BaseException):
class UserNotFoundException(CustomException):
def __init__(self):
super().__init__('User not found.', status_code=404)


class UserIsCorrectException(BaseException):
class UserIsCorrectException(CustomException):
def __init__(self):
super().__init__('User is correct.', status_code=401)


# Tokens
class TokenInvalidException(BaseException):
class TokenInvalidException(CustomException):
def __init__(self):
super().__init__('Invalid token.', status_code=401)


class TokenExpiredException(BaseException):
class TokenExpiredException(CustomException):
def __init__(self):
super().__init__('Token expired.', status_code=401)

0 comments on commit 63da0ce

Please sign in to comment.