Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix external not found fastapi response #62

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ async def lifespan(_app: FastAPI):
)

app.add_exception_handler(RequestValidationError, utils.handlers.request_validation_exception_handler)

app.add_exception_handler(utils.response.ErrorResponse, utils.handlers.error_response_handler)

app.add_exception_handler(500, utils.handlers.internal_exception_handler)
app.add_exception_handler(404, utils.handlers.external_not_found_handler)
2 changes: 1 addition & 1 deletion src/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def signin(request: RQ.auth.signin):

if user is None:
raise ErrorResponse(
code=ErrorCodes.ENTITY_NOT_FOUND, http_status_code=http_status.HTTP_404_NOT_FOUND, message="User not found"
code=ErrorCodes.NOT_FOUND, http_status_code=http_status.HTTP_404_NOT_FOUND, message="User not found"
)

if not utils.auth.verify_password(request.password, user.hashed_password):
Expand Down
10 changes: 10 additions & 0 deletions src/utils/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ async def internal_exception_handler(_request: Request, exc: Exception):
"error": {"code": response.ErrorCodes.INTERNAL_SERVER_ERROR.value, "message": "Internal Server Error"},
},
)


async def external_not_found_handler(_request: Request, _exc: Exception):
return JSONResponse(
status_code=404,
content={
"ok": False,
"error": {"code": response.ErrorCodes.NOT_FOUND.value, "message": "Endpoint Not Found"},
},
)
2 changes: 1 addition & 1 deletion src/utils/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ErrorCodes(Enum):
UNPROCESSABLE_ENTITY = 2
TOKEN_EXPIRED = 3
TOKEN_VALIDATION_FAILED = 4
ENTITY_NOT_FOUND = 5
NOT_FOUND = 5
ACCESS_DENIED = 6
DOMAIN_ALREADY_TAKEN = 7
EMAIL_ALREADY_TAKEN = 8
Expand Down
2 changes: 1 addition & 1 deletion tests/src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export enum ErrorCodes {
UNPROCESSABLE_ENTITY,
TOKEN_EXPIRED,
TOKEN_VALIDATION_FAILED,
ENTITY_NOT_FOUND,
NOT_FOUND,
ACCESS_DENIED,
DOMAIN_ALREADY_TAKEN,
EMAIL_ALREADY_TAKEN
Expand Down