@@ -147,6 +147,34 @@ def test_strip_extras_post_hook_exclude_status_code(self):
147147 == b'{"type":"something-wrong","title":"This is an error.","status":500,"a":"b","detail":"something bad"}'
148148 )
149149
150+ def test_strip_extras_post_hook_include_status_code (self ):
151+ request = mock .Mock (headers = {})
152+ exc = SomethingWrongError ("something bad" , a = "b" )
153+
154+ eh = handler .ExceptionHandler (
155+ post_hooks = [handler .StripExtrasPostHook (include_status_codes = [500 ], enabled = True )],
156+ )
157+ response = eh (request , exc )
158+
159+ assert (
160+ response .body
161+ == b'{"type":"something-wrong","title":"This is an error.","status":500,"detail":"something bad"}'
162+ )
163+
164+ def test_strip_extras_post_hook_include_status_code_correctly_allows_other_codes_through (self ):
165+ request = mock .Mock (headers = {})
166+ exc = SomethingWrongError ("something bad" , a = "b" )
167+
168+ eh = handler .ExceptionHandler (
169+ post_hooks = [handler .StripExtrasPostHook (include_status_codes = [400 ], enabled = True )],
170+ )
171+ response = eh (request , exc )
172+
173+ assert (
174+ response .body
175+ == b'{"type":"something-wrong","title":"This is an error.","status":500,"a":"b","detail":"something bad"}'
176+ )
177+
150178 def test_strip_extras_post_hook_custom_mandatory (self ):
151179 request = mock .Mock (headers = {})
152180 exc = SomethingWrongError ("something bad" , a = "b" )
0 commit comments