Skip to content

Commit

Permalink
fix: Normalizes the UnauthorizationError for the API response (#1748)
Browse files Browse the repository at this point in the history
  • Loading branch information
frascuchon committed Oct 5, 2022
1 parent e82fd13 commit 6a68048
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/rubrix/server/errors/api_errors.py
Expand Up @@ -26,17 +26,6 @@
_LOGGER = logging.getLogger("rubrix")


class UnauthorizedError(HTTPException):
"""Unauthorized error"""

def __init__(self):
super().__init__(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
headers={"WWW-Authenticate": "Bearer"},
)


class RubrixErrorDetail(BaseModel):
code: str
params: Dict[str, Any]
Expand Down
9 changes: 9 additions & 0 deletions src/rubrix/server/errors/base_errors.py
Expand Up @@ -95,6 +95,15 @@ def __init__(self, message: Optional[str] = None):
self.detail = message or "Operation not allowed"


class UnauthorizedError(RubrixServerError):
"""Unauthorized operation"""

HTTP_STATUS = status.HTTP_401_UNAUTHORIZED

def __init__(self, message: Optional[str] = None):
self.detail = message or "Could not validate credentials"


class BadRequestError(RubrixServerError):
"""Generic bad request error"""

Expand Down

0 comments on commit 6a68048

Please sign in to comment.