Total Complexity | 2 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from hapic.error import DefaultErrorBuilder |
||
2 | from hapic.processor import ProcessValidationError |
||
3 | from tracim_backend.error_code import ERROR_CODE_GENERIC_SCHEMA_VALIDATION_ERROR |
||
4 | |||
5 | |||
6 | class ErrorSchema(DefaultErrorBuilder): |
||
7 | """ |
||
8 | This class is both a builder and a Marshmallow Schema, His named is used for |
||
9 | swagger ui error schema. That's why we call it ErrorSchema To have |
||
10 | a nice naming in swagger ui. |
||
11 | """ |
||
12 | def build_from_exception( |
||
13 | self, |
||
14 | exception: Exception, |
||
15 | include_traceback: bool = False, |
||
16 | ) -> dict: |
||
17 | error_dict = DefaultErrorBuilder.build_from_exception( |
||
18 | self, |
||
19 | exception, |
||
20 | include_traceback |
||
21 | ) |
||
22 | code = getattr(exception, 'error_code', None) |
||
23 | error_dict['code'] = code |
||
24 | return error_dict |
||
25 | |||
26 | def build_from_validation_error( |
||
27 | self, |
||
28 | error: ProcessValidationError, |
||
29 | ) -> dict: |
||
30 | error_dict = DefaultErrorBuilder.build_from_validation_error(self, error) # nopep8 |
||
31 | error_dict['code'] = ERROR_CODE_GENERIC_SCHEMA_VALIDATION_ERROR |
||
32 | return error_dict |
||
33 |