Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
feat: add UnauthorizedError
Browse files Browse the repository at this point in the history
  • Loading branch information
HamidMolareza committed Mar 31, 2023
1 parent fbf0ed7 commit a60234b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
27 changes: 27 additions & 0 deletions def_result/ResultDetails/Errors/UnauthorizedError.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import Any, Dict, List, Optional

from def_result.ResultDetails.ErrorDetail import ErrorDetail


class UnauthorizedError(ErrorDetail):
""" An error that occurs when a user is not authorized to perform a certain action.
This error is a subclass of `ErrorDetail`, which provides additional details about the error.
Args:
title (str, optional): A title for the error. Defaults to "Unauthorized Error".
message (str, optional): A message describing the error. Defaults to None.
code (int, optional): An error code associated with the error. Defaults to 401.
errors (Dict[str, str], optional): A dictionary containing additional error details. Defaults to None.
exception (Exception, optional): An exception that caused the error. Defaults to None.
more_data (List[Any], optional): A list of additional data associated with the error. Defaults to None.
"""

def __init__(self, title: Optional[str] = "Unauthorized Error",
message: Optional[str] = None,
code: Optional[int] = 401,
errors: Optional[Dict[str, str]] = None,
exception: Optional[Exception] = None,
more_data: Optional[List[Any]] = None):
super().__init__(title=title, message=message, code=code, errors=errors, exception=exception,
more_data=more_data)
25 changes: 25 additions & 0 deletions tests/ResultDetails/Errors/test_UnauthorizedError.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest

from def_result.ResultDetails.Errors.UnauthorizedError import UnauthorizedError
from tests.helpers import assert_error_detail


class TestUnauthorizedError(unittest.TestCase):
def test_init_without_args(self):
detail = UnauthorizedError()

assert_error_detail(test_class=self, error_detail=detail, title="Unauthorized Error",
code=401)

def test_init_with_args(self):
exception = Exception("fake")
detail = UnauthorizedError(title="title", message="message", code=100, more_data=["message"],
errors={"key": "message"}, exception=exception)

assert_error_detail(test_class=self, error_detail=detail, title="title",
code=100, message="message", more_data=["message"],
errors={"key": "message"}, exception=exception)


if __name__ == '__main__':
unittest.main()

0 comments on commit a60234b

Please sign in to comment.