Skip to content

Commit 4c47081

Browse files
committed
Switch from ResponseHeadersValidationError to RuntimeError
Response instances cannot be validated, and hence it is considered a programming error (RuntimeError) to try. It isn't clear why b5c610b choose a ResponseHeadersValidationError, but it doesn't make sense as the exception type.
1 parent b20121e commit 4c47081

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/quart_schema/validation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ async def wrapper(*args: Any, **kwargs: Any) -> Any:
223223

224224
if isinstance(value, (Response, WerkzeugResponse)):
225225
if status == status_code:
226-
raise ResponseHeadersValidationError()
226+
raise RuntimeError("Cannot validate Response instance")
227227
else:
228228
return result
229229

tests/test_validation.py

+14
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ async def item() -> ResponseReturnValue:
211211
assert response.status_code == 302
212212

213213

214+
async def test_response_validation_of_response() -> None:
215+
app = Quart(__name__)
216+
QuartSchema(app)
217+
218+
@app.route("/")
219+
@validate_response(PyItem)
220+
async def item() -> ResponseReturnValue:
221+
return Response(200)
222+
223+
test_client = app.test_client()
224+
response = await test_client.get("/")
225+
assert response.status_code == 500
226+
227+
214228
@pytest.mark.parametrize(
215229
"return_value, status",
216230
[

0 commit comments

Comments
 (0)