-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jamshale <jamiehalebc@gmail.com>
- Loading branch information
Showing
10 changed files
with
134 additions
and
108 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,28 @@ | ||
from pymongo.errors import WriteError | ||
from fastapi import HTTPException | ||
from fastapi import status as http_status | ||
import structlog | ||
|
||
logger = structlog.getLogger(__name__) | ||
|
||
|
||
def raise_appropriate_http_exception(err: WriteError, exists_msg: str = None): | ||
if err.code == 11000: | ||
raise HTTPException( | ||
status_code=http_status.HTTP_409_CONFLICT, | ||
detail=exists_msg, | ||
) | ||
else: | ||
logger.error("Unknown error", err=err) | ||
raise HTTPException( | ||
status_code=http_status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
detail="The server was unable to process the request", | ||
) | ||
|
||
|
||
def check_and_raise_not_found_http_exception(resp): | ||
if resp is None: | ||
raise HTTPException( | ||
status_code=http_status.HTTP_404_NOT_FOUND, | ||
detail="The requested resource wasn't found", | ||
) |
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.