error raise now locates loc
This commit is contained in:
@@ -6,7 +6,11 @@ from fastapi import Request, HTTPException, status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from api_objects.errors.errorMessages import EXCEPTION_DICTS, ERRORS_DICT, ERRORS_LANG
|
||||
from api_objects.errors.errorHandlers import HTTPExceptionEvyos, HTTPExceptionAnyHandler, HTTPExceptionEvyosHandler
|
||||
from api_objects.errors.errorHandlers import (
|
||||
HTTPExceptionEvyos,
|
||||
HTTPExceptionAnyHandler,
|
||||
HTTPExceptionEvyosHandler,
|
||||
)
|
||||
|
||||
from middlewares.token_middleware import AuthHeaderMiddleware
|
||||
from application.create_file import create_app
|
||||
@@ -27,14 +31,16 @@ app.add_middleware(
|
||||
app.add_middleware(AuthHeaderMiddleware)
|
||||
|
||||
# Initialize Exception and ExceptionInstance handlers
|
||||
CustomExceptionHandler = HTTPExceptionEvyosHandler(**dict(
|
||||
statuses=status,
|
||||
exceptions=HTTPException,
|
||||
response_model=JSONResponse,
|
||||
exceptions_dict=EXCEPTION_DICTS,
|
||||
errors_dict=ERRORS_DICT,
|
||||
error_language_dict=ERRORS_LANG
|
||||
))
|
||||
CustomExceptionHandler = HTTPExceptionEvyosHandler(
|
||||
**dict(
|
||||
statuses=status,
|
||||
exceptions=HTTPException,
|
||||
response_model=JSONResponse,
|
||||
exceptions_dict=EXCEPTION_DICTS,
|
||||
errors_dict=ERRORS_DICT,
|
||||
error_language_dict=ERRORS_LANG,
|
||||
)
|
||||
)
|
||||
CustomExceptionAnyHandler = HTTPExceptionAnyHandler(response_model=JSONResponse)
|
||||
|
||||
# Register error handlers with bound methods
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import json
|
||||
from typing import Union
|
||||
from fastapi import status
|
||||
from fastapi.requests import Request
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
from api_objects import OccupantTokenObject, EmployeeTokenObject
|
||||
from api_objects.auth.token_objects import CompanyToken, OccupantToken
|
||||
from api_services.templates.password_templates import (
|
||||
password_is_changed_template,
|
||||
change_your_password_template,
|
||||
@@ -36,6 +33,13 @@ from api_validations.validations_response import (
|
||||
from ApiServices.api_handlers.auth_actions.auth import AuthActions
|
||||
from api_configs import Auth, ApiStatic
|
||||
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
|
||||
from api_objects import (
|
||||
OccupantTokenObject,
|
||||
EmployeeTokenObject,
|
||||
CompanyToken,
|
||||
OccupantToken,
|
||||
HTTPExceptionEvyos,
|
||||
)
|
||||
|
||||
from databases import (
|
||||
Companies,
|
||||
@@ -55,9 +59,7 @@ from databases import (
|
||||
RelationshipEmployee2Build,
|
||||
)
|
||||
|
||||
from api_services import (
|
||||
send_email,
|
||||
)
|
||||
from api_services import send_email
|
||||
|
||||
|
||||
class AuthenticationLoginEventMethods(MethodToEvent):
|
||||
@@ -74,26 +76,12 @@ class AuthenticationLoginEventMethods(MethodToEvent):
|
||||
|
||||
@classmethod
|
||||
def authentication_login_with_domain_and_creds(cls, data: Login, request: Request):
|
||||
from api_objects import HTTPExceptionEvyos
|
||||
|
||||
raise HTTPExceptionEvyos(
|
||||
error_code="UNKNOWN_ERROR",
|
||||
lang="en",
|
||||
)
|
||||
access_dict = Users.login_user_with_credentials(data=data, request=request)
|
||||
found_user = access_dict.get("user")
|
||||
Users.client_arrow = DateTimeLocal(
|
||||
is_client=True, timezone=found_user.local_timezone
|
||||
)
|
||||
if not found_user:
|
||||
# UserLogger.log_login_attempt(
|
||||
# request,
|
||||
# None,
|
||||
# data.domain,
|
||||
# data.access_key,
|
||||
# success=False,
|
||||
# error="Invalid credentials",
|
||||
# )
|
||||
return ResponseHandler.unauthorized("Invalid credentials")
|
||||
return ResponseHandler.success(
|
||||
message="User logged in successfully",
|
||||
@@ -104,11 +92,6 @@ class AuthenticationLoginEventMethods(MethodToEvent):
|
||||
"user": found_user.get_dict(),
|
||||
},
|
||||
)
|
||||
# except Exception as e:
|
||||
# # UserLogger.log_login_attempt(
|
||||
# # request, None, data.domain, data.access_key, success=False, error=str(e)
|
||||
# # )
|
||||
# raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=str(e))
|
||||
|
||||
|
||||
class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
@@ -128,9 +111,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
cls, data: EmployeeSelection, token_dict: EmployeeTokenObject, request: Request
|
||||
):
|
||||
"""Handle employee company selection"""
|
||||
Users.client_arrow = DateTimeLocal(
|
||||
is_client=True, timezone=token_dict.local_timezone
|
||||
)
|
||||
Users.client_arrow = DateTimeLocal(is_client=True, timezone=token_dict.timezone)
|
||||
if data.company_uu_id not in token_dict.companies_uu_id_list:
|
||||
return ResponseHandler.unauthorized(
|
||||
"Company not found in user's company list"
|
||||
|
||||
Reference in New Issue
Block a user