Skip to content

Commit aaadab2

Browse files
popadiAdrian Pop
andauthored
#307: Allow custom headers in self.error view method (#437)
Co-authored-by: Adrian Pop <[email protected]>
1 parent 2b8ef5a commit aaadab2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

faust/web/views.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,11 @@ def notfound(self, reason: str = "Not Found", **kwargs: Any) -> Response:
299299
"""
300300
return self.error(404, reason, **kwargs)
301301

302-
def error(self, status: int, reason: str, **kwargs: Any) -> Response:
302+
def error(
303+
self, status: int, reason: str, headers: MutableMapping = None, **kwargs: Any
304+
) -> Response:
303305
"""Create error JSON response."""
304-
return self.json({"error": reason, **kwargs}, status=status)
306+
return self.json({"error": reason, **kwargs}, status=status, headers=headers)
305307

306308

307309
def takes_model(Model: Type[ModelT]) -> ViewDecorator:

tests/unit/web/test_views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ def test_route(self, *, view, web):
204204
assert res is handler
205205

206206
def test_error(self, *, view, web):
207-
response = view.error(303, "foo", arg="bharg")
207+
response = view.error(303, "foo", arg="bharg", headers={"k": "v"})
208208
web.json.assert_called_once_with(
209209
{"error": "foo", "arg": "bharg"},
210210
status=303,
211211
reason=None,
212-
headers=None,
213212
content_type=None,
213+
headers={"k": "v"},
214214
)
215215
assert response is web.json()
216216

0 commit comments

Comments
 (0)