Browse Source

fix default error format

Bastien Sevajol 6 years ago
parent
commit
1a1bc47ec9
5 changed files with 16 additions and 16 deletions
  1. 2 2
      example.py
  2. 8 8
      hapic/processor.py
  3. 1 1
      setup.py
  4. 3 3
      tests/unit/test_decorator.py
  5. 2 2
      tests/unit/test_processor.py

+ 2 - 2
example.py View File

3
 
3
 
4
 
4
 
5
 class ErrorResponseSchema(marshmallow.Schema):
5
 class ErrorResponseSchema(marshmallow.Schema):
6
-    error_message = marshmallow.fields.String(required=True)
7
-    error_details = marshmallow.fields.Dict(required=True)
6
+    message = marshmallow.fields.String(required=True)
7
+    details = marshmallow.fields.Dict(required=True)
8
 
8
 
9
 
9
 
10
 class HelloResponseSchema(marshmallow.Schema):
10
 class HelloResponseSchema(marshmallow.Schema):

+ 8 - 8
hapic/processor.py View File

23
 class ProcessValidationError(object):
23
 class ProcessValidationError(object):
24
     def __init__(
24
     def __init__(
25
         self,
25
         self,
26
-        error_message: str,
27
-        error_details: dict,
26
+        message: str,
27
+        details: dict,
28
     ) -> None:
28
     ) -> None:
29
-        self.error_message = error_message
30
-        self.error_details = error_details
29
+        self.message = message
30
+        self.details = details
31
 
31
 
32
 
32
 
33
 class ProcessorInterface(object):
33
 class ProcessorInterface(object):
71
         data = self.schema.dump(data).data
71
         data = self.schema.dump(data).data
72
         errors = self.schema.load(data).errors
72
         errors = self.schema.load(data).errors
73
         return ProcessValidationError(
73
         return ProcessValidationError(
74
-            error_message='Validation error of output data',
75
-            error_details=errors,
74
+            message='Validation error of output data',
75
+            details=errors,
76
         )
76
         )
77
 
77
 
78
 
78
 
91
     def get_validation_error(self, data: dict) -> ProcessValidationError:
91
     def get_validation_error(self, data: dict) -> ProcessValidationError:
92
         marshmallow_errors = self.schema.load(data).errors
92
         marshmallow_errors = self.schema.load(data).errors
93
         return ProcessValidationError(
93
         return ProcessValidationError(
94
-            error_message='Validation error of input data',
95
-            error_details=marshmallow_errors,
94
+            message='Validation error of input data',
95
+            details=marshmallow_errors,
96
         )
96
         )
97
 
97
 

+ 1 - 1
setup.py View File

23
     # Versions should comply with PEP440.  For a discussion on single-sourcing
23
     # Versions should comply with PEP440.  For a discussion on single-sourcing
24
     # the version across setup.py and the project code, see
24
     # the version across setup.py and the project code, see
25
     # https://packaging.python.org/en/latest/single_source_version.html
25
     # https://packaging.python.org/en/latest/single_source_version.html
26
-    version='0.0.4',
26
+    version='0.0.4.1',
27
 
27
 
28
     description='HTTP api input/output manager',
28
     description='HTTP api input/output manager',
29
     # long_description=long_description,
29
     # long_description=long_description,

+ 3 - 3
tests/unit/test_decorator.py View File

58
         request_context: RequestParameters,
58
         request_context: RequestParameters,
59
     ) -> ProcessValidationError:
59
     ) -> ProcessValidationError:
60
         return ProcessValidationError(
60
         return ProcessValidationError(
61
-            error_details={
61
+            details={
62
                 'original_request_context': request_context,
62
                 'original_request_context': request_context,
63
             },
63
             },
64
-            error_message='ERROR',
64
+            message='ERROR',
65
         )
65
         )
66
 
66
 
67
 
67
 
197
         assert 'http_code' in result
197
         assert 'http_code' in result
198
         assert result['http_code'] == HTTPStatus.INTERNAL_SERVER_ERROR
198
         assert result['http_code'] == HTTPStatus.INTERNAL_SERVER_ERROR
199
         assert 'original_error' in result
199
         assert 'original_error' in result
200
-        assert result['original_error'].error_details == {
200
+        assert result['original_error'].details == {
201
             'name': ['Missing data for required field.']
201
             'name': ['Missing data for required field.']
202
         }
202
         }
203
 
203
 

+ 2 - 2
tests/unit/test_processor.py View File

61
             processor.process(tested_data)
61
             processor.process(tested_data)
62
 
62
 
63
         errors = processor.get_validation_error(tested_data)
63
         errors = processor.get_validation_error(tested_data)
64
-        assert errors.error_details
65
-        assert 'first_name' in errors.error_details
64
+        assert errors.details
65
+        assert 'first_name' in errors.details
66
 
66
 
67
     def test_unit__marshmallow_input_processor__ok__completed_data(self):
67
     def test_unit__marshmallow_input_processor__ok__completed_data(self):
68
         processor = MarshmallowInputProcessor()
68
         processor = MarshmallowInputProcessor()