Browse Source

Merge pull request #73 from algoo/develop

Bastien Sevajol 6 years ago
parent
commit
53657dea22
No account linked to committer's email
3 changed files with 52 additions and 2 deletions
  1. 34 0
      PACKAGING.md
  2. 2 1
      hapic/context.py
  3. 16 1
      hapic/ext/flask/context.py

+ 34 - 0
PACKAGING.md View File

@@ -0,0 +1,34 @@
1
+# Packaging of hapic
2
+
3
+## Prerequisite
4
+
5
+Prepare a `~/.pypirc` configuration file, eg:
6
+
7
+    [distutils]
8
+    index-servers = pypi
9
+
10
+    [pypi]
11
+    repository: https://upload.pypi.org/legacy/
12
+    username: algoo
13
+
14
+Upgrade or install packages:
15
+
16
+    pip install --upgrade setuptools wheel twine
17
+
18
+## Package and distribute
19
+
20
+Checkout on branch `master` (or other branch if you know what you are doing):
21
+
22
+    git checkout master
23
+
24
+Build the package:
25
+
26
+    python setup.py sdist
27
+
28
+Upload it:
29
+
30
+    twine upload dist/*
31
+
32
+If you want give a try before, use:
33
+
34
+    twine upload --repository-url https://test.pypi.org/legacy/ dist/hapic-VERSION.tar.gz

+ 2 - 1
hapic/context.py View File

@@ -206,8 +206,9 @@ class BaseContext(ContextInterface):
206 206
                             exc,
207 207
                             include_traceback=self.is_debug(),
208 208
                         )
209
+                        dumped = error_builder.dump(error_body).data
209 210
                         return self.get_response(
210
-                            json.dumps(error_body),
211
+                            json.dumps(dumped),
211 212
                             handled_exception.http_code,
212 213
                         )
213 214
                 raise exc

+ 16 - 1
hapic/ext/flask/context.py View File

@@ -166,7 +166,22 @@ class FlaskContext(BaseContext):
166 166
         exception_class: typing.Type[Exception],
167 167
         http_code: int,
168 168
     ) -> None:
169
-        raise NotImplementedError('TODO')
169
+        def return_response_error(exc):
170
+            error_builder = self.get_default_error_builder()
171
+            error_body = error_builder.build_from_exception(
172
+                exc,
173
+                include_traceback=self.is_debug(),
174
+            )
175
+            dumped = error_builder.dump(error_body).data
176
+            return self.get_response(
177
+                json.dumps(dumped),
178
+                http_code,
179
+            )
180
+
181
+        self.app.register_error_handler(
182
+            exception_class,
183
+            return_response_error,
184
+        )
170 185
 
171 186
     def is_debug(self) -> bool:
172 187
         return self.debug