-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring: added query parameter check and renamed pdfa parameter t…
…o profile
- Loading branch information
1 parent
ff56eed
commit d3d5b17
Showing
12 changed files
with
144 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import logging | ||
from typing import Callable | ||
|
||
from fastapi import HTTPException, Request, Response | ||
from fastapi.routing import APIRoute | ||
from starlette.background import BackgroundTask | ||
from starlette.responses import JSONResponse | ||
|
||
_logger = logging.getLogger("teal.http") | ||
|
||
|
||
class CheckUnknownQueryParamsRouter(APIRoute): | ||
|
||
def get_route_handler(self) -> Callable: | ||
original_route_handler = super().get_route_handler() | ||
known_params = [param.name for param in self.dependant.query_params] | ||
|
||
async def custom_route_handler(request: Request) -> Response: | ||
unknown_params = [ | ||
qp for qp in request.query_params if qp not in known_params | ||
] | ||
|
||
if any(unknown_params): | ||
_logger.debug( | ||
f"Unknown request parameters: {unknown_params}, supported parameters are {known_params}" | ||
) | ||
raise HTTPException( | ||
status_code=400, | ||
detail=f"Unknown request parameters: {unknown_params}, supported parameters are {known_params}", | ||
) | ||
|
||
return await original_route_handler(request) | ||
|
||
return custom_route_handler | ||
|
||
|
||
def create_json_response(content, background: BackgroundTask = None): | ||
return JSONResponse(content=content, background=background) | ||
|
||
|
||
def create_json_err_response_from_exception( | ||
ex: Exception, background: BackgroundTask = None | ||
): | ||
return JSONResponse( | ||
status_code=500, | ||
content={ | ||
"message": f"{ex}", | ||
}, | ||
background=background, | ||
) | ||
|
||
|
||
def create_json_err_response( | ||
code: int, message: str, background: BackgroundTask = None | ||
): | ||
return JSONResponse( | ||
status_code=code, | ||
content={ | ||
"message": message, | ||
}, | ||
background=background, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.