Coverage for microservice_websocket/app/utils/exceptions.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.0.0, created at 2022-12-20 14:31 +0000

1from fastapi import HTTPException, status 

2 

3 

4class DuplicateException(HTTPException): 

5 def __init__(self, field_name: str): 

6 super().__init__( 

7 status_code=status.HTTP_400_BAD_REQUEST, 

8 detail=f"Duplicate field '{field_name}'", 

9 ) 

10 

11 

12class NotFoundException(HTTPException): 

13 def __init__(self, detail: str | None = None): 

14 detail = "Not found" if detail is None else f"'{detail}' not found" 

15 super().__init__(status_code=status.HTTP_404_NOT_FOUND, detail=detail)