backend.components.camera_verification.error_handling.errorConfig

 1from backend.components.camera_verification.qrcode.qrcodeService import (
 2    InvalidCodeError, QRCodeError, MultipleCodesError, NoCodeFoundError, ExpiredCodeError
 3)
 4from backend.components.camera_verification.faceid.faceidService import (
 5    MultipleWorkersError, NoFacesFoundError, FaceNotMatchingError, FaceIDError
 6)
 7
 8class ErrorResponse:
 9    '''
10    Response that is sent to the camera front-end.
11
12    **Parameters**:
13    - `code` (int): "Error" code for the response, refer to the `EXCEPTION_MAP` for more info. Similar to program exit code.
14    - `message` (str): Textual, human readable description for `ErrorResponse.code`.
15    - `logged` (bool): Decides whether this kind of entry should be logged or not. For use in backend.
16    '''
17    def __init__(self, code, message, logged=True):
18        self.code: int = code
19        self.message: str = message
20        self.logged: bool = logged
21        
22    def asdict(self):
23        return {
24            'code': self.code,
25            'message': self.message,
26            'logged': self.logged,
27        }
28    
29    def __repr__(self):
30        return str(self.asdict())
31        
32
33EXCEPTION_MAP = {
34    Exception                : ErrorResponse(-1, "Nieznany błąd, poinformuj producenta."),
35    type(None)               : ErrorResponse(0, "Weryfikacja udana."),
36    NoCodeFoundError         : ErrorResponse(1, "Puste zdjęcie. Nie wykryto kodu QR.", logged=False),
37    NoFacesFoundError        : ErrorResponse(2, "Puste zdjęcie. Nie wykryto twarzy.", logged=False),
38    QRCodeError              : ErrorResponse(10, "Ogólny błąd kodu QR."),
39    InvalidCodeError         : ErrorResponse(11, "Podany kod QR jest niepoprawny."),
40    MultipleCodesError       : ErrorResponse(12, "Podano więcej niż jeden kod QR."),
41    ExpiredCodeError         : ErrorResponse(13, "Przepustka wygasła."),
42    FaceIDError              : ErrorResponse(20, "Ogólny błąd weryfikacji twarzy."),
43    FaceNotMatchingError     : ErrorResponse(21, "Wykryta twarz nie pasuje do kodu QR."),
44    MultipleWorkersError     : ErrorResponse(22, "Wykryto więcej niż jednego pracownika."),
45}
46"""
47Maps Exceptions to ErrorResponse object definitions with various status codes and messages, 
48as well as information whether to log the event.
49"""
class ErrorResponse:
 9class ErrorResponse:
10    '''
11    Response that is sent to the camera front-end.
12
13    **Parameters**:
14    - `code` (int): "Error" code for the response, refer to the `EXCEPTION_MAP` for more info. Similar to program exit code.
15    - `message` (str): Textual, human readable description for `ErrorResponse.code`.
16    - `logged` (bool): Decides whether this kind of entry should be logged or not. For use in backend.
17    '''
18    def __init__(self, code, message, logged=True):
19        self.code: int = code
20        self.message: str = message
21        self.logged: bool = logged
22        
23    def asdict(self):
24        return {
25            'code': self.code,
26            'message': self.message,
27            'logged': self.logged,
28        }
29    
30    def __repr__(self):
31        return str(self.asdict())

Response that is sent to the camera front-end.

Parameters:

  • code (int): "Error" code for the response, refer to the EXCEPTION_MAP for more info. Similar to program exit code.
  • message (str): Textual, human readable description for ErrorResponse.code.
  • logged (bool): Decides whether this kind of entry should be logged or not. For use in backend.
ErrorResponse(code, message, logged=True)
18    def __init__(self, code, message, logged=True):
19        self.code: int = code
20        self.message: str = message
21        self.logged: bool = logged
code: int
message: str
logged: bool
def asdict(self):
23    def asdict(self):
24        return {
25            'code': self.code,
26            'message': self.message,
27            'logged': self.logged,
28        }
EXCEPTION_MAP = {<class 'Exception'>: {'code': -1, 'message': 'Nieznany błąd, poinformuj producenta.', 'logged': True}, <class 'NoneType'>: {'code': 0, 'message': 'Weryfikacja udana.', 'logged': True}, <class 'backend.components.camera_verification.qrcode.qrcodeService.NoCodeFoundError'>: {'code': 1, 'message': 'Puste zdjęcie. Nie wykryto kodu QR.', 'logged': False}, <class 'backend.components.camera_verification.faceid.faceidService.NoFacesFoundError'>: {'code': 2, 'message': 'Puste zdjęcie. Nie wykryto twarzy.', 'logged': False}, <class 'backend.components.camera_verification.qrcode.qrcodeService.QRCodeError'>: {'code': 10, 'message': 'Ogólny błąd kodu QR.', 'logged': True}, <class 'backend.components.camera_verification.qrcode.qrcodeService.InvalidCodeError'>: {'code': 11, 'message': 'Podany kod QR jest niepoprawny.', 'logged': True}, <class 'backend.components.camera_verification.qrcode.qrcodeService.MultipleCodesError'>: {'code': 12, 'message': 'Podano więcej niż jeden kod QR.', 'logged': True}, <class 'backend.components.camera_verification.qrcode.qrcodeService.ExpiredCodeError'>: {'code': 13, 'message': 'Przepustka wygasła.', 'logged': True}, <class 'backend.components.camera_verification.faceid.faceidService.FaceIDError'>: {'code': 20, 'message': 'Ogólny błąd weryfikacji twarzy.', 'logged': True}, <class 'backend.components.camera_verification.faceid.faceidService.FaceNotMatchingError'>: {'code': 21, 'message': 'Wykryta twarz nie pasuje do kodu QR.', 'logged': True}, <class 'backend.components.camera_verification.faceid.faceidService.MultipleWorkersError'>: {'code': 22, 'message': 'Wykryto więcej niż jednego pracownika.', 'logged': True}}

Maps Exceptions to ErrorResponse object definitions with various status codes and messages, as well as information whether to log the event.