|
1 | | -from http import HTTPStatus |
2 | | - |
3 | | -from fastapi import HTTPException, status |
4 | | - |
5 | | - |
6 | | -class CustomException(HTTPException): |
7 | | - def __init__(self, status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR, detail: str | None = None): |
8 | | - if not detail: |
9 | | - detail = HTTPStatus(status_code).description |
10 | | - super().__init__(status_code=status_code, detail=detail) |
11 | | - |
12 | | - |
13 | | -class BadRequestException(CustomException): |
14 | | - def __init__(self, detail: str | None = None): |
15 | | - super().__init__(status_code=status.HTTP_400_BAD_REQUEST, detail=detail) |
16 | | - |
17 | | - |
18 | | -class NotFoundException(CustomException): |
19 | | - def __init__(self, detail: str | None = None): |
20 | | - super().__init__(status_code=status.HTTP_404_NOT_FOUND, detail=detail) |
21 | | - |
22 | | - |
23 | | -class ForbiddenException(CustomException): |
24 | | - def __init__(self, detail: str | None = None): |
25 | | - super().__init__(status_code=status.HTTP_403_FORBIDDEN, detail=detail) |
26 | | - |
27 | | - |
28 | | -class UnauthorizedException(CustomException): |
29 | | - def __init__(self, detail: str | None = None): |
30 | | - super().__init__(status_code=status.HTTP_401_UNAUTHORIZED, detail=detail) |
31 | | - |
32 | | - |
33 | | -class UnprocessableEntityException(CustomException): |
34 | | - def __init__(self, detail: str | None = None): |
35 | | - super().__init__(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=detail) |
36 | | - |
37 | | - |
38 | | -class DuplicateValueException(CustomException): |
39 | | - def __init__(self, detail: str | None = None): |
40 | | - super().__init__(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=detail) |
41 | | - |
42 | | - |
43 | | -class RateLimitException(CustomException): |
44 | | - def __init__(self, detail: str | None = None): |
45 | | - super().__init__(status_code=status.HTTP_429_TOO_MANY_REQUESTS, detail=detail) |
| 1 | +# ruff: noqa |
| 2 | +from fastcrud.exceptions.http_exceptions import ( |
| 3 | + CustomException, |
| 4 | + BadRequestException, |
| 5 | + NotFoundException, |
| 6 | + ForbiddenException, |
| 7 | + UnauthorizedException, |
| 8 | + UnprocessableEntityException, |
| 9 | + DuplicateValueException, |
| 10 | + RateLimitException, |
| 11 | +) |
0 commit comments