1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

Fix password login exception

This commit is contained in:
Steffo 2020-05-28 16:59:31 +02:00
parent c2d2d2543f
commit 3d69b62d7d
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
4 changed files with 13 additions and 7 deletions

View file

@ -34,7 +34,7 @@ class ApiLoginRoyalnetStar(ApiStar):
raise NotFoundError("User not found")
pswd_check = user.test_password(password)
if not pswd_check:
raise ApiError("Invalid password")
raise UnauthorizedError("Invalid password")
token: Token = TokenT.generate(alchemy=self.alchemy, user=user, expiration_delta=datetime.timedelta(days=7))
session.add(token)
await ru.asyncify(session.commit)

View file

@ -9,7 +9,7 @@ from .apierrors import \
ParameterError, \
MissingParameterError, \
InvalidParameterError, \
NotImplementedError, \
MethodNotImplementedError, \
UnsupportedError
@ -29,6 +29,6 @@ __all__ = [
"ParameterError",
"MissingParameterError",
"InvalidParameterError",
"NotImplementedError",
"MethodNotImplementedError",
"UnsupportedError",
]

View file

@ -6,6 +6,10 @@ class NotFoundError(ApiError):
pass
class UnauthorizedError(ApiError):
pass
class ForbiddenError(ApiError):
pass
@ -26,9 +30,9 @@ class InvalidParameterError(ParameterError):
pass
class NotImplementedError(ApiError):
class MethodNotImplementedError(ApiError):
pass
class UnsupportedError(NotImplementedError):
class UnsupportedError(MethodNotImplementedError):
pass

View file

@ -32,11 +32,13 @@ class ApiStar(PageStar, ABC):
apidata = ApiData(data=data, star=self, method=request.method)
try:
response = await self.api(apidata)
except UnauthorizedError as e:
return api_error(e, code=401)
except NotFoundError as e:
return api_error(e, code=404)
except ForbiddenError as e:
return api_error(e, code=403)
except NotImplementedError as e:
except MethodNotImplementedError as e:
return api_error(e, code=501)
except BadRequestError as e:
return api_error(e, code=400)
@ -49,7 +51,7 @@ class ApiStar(PageStar, ABC):
await apidata.session_close()
async def api(self, data: ApiData) -> ru.JSON:
raise NotImplementedError()
raise MethodNotImplementedError()
@classmethod
def swagger(cls) -> ru.JSON: