Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return 500 status code when route raise #382

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions integration_tests/base_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,16 @@ def file_download_async():
return serve_file(file_path)


@app.get("/sync/raise")
def sync_raise():
raise Exception()


@app.get("/async/raise")
async def async_raise():
raise Exception()


if __name__ == "__main__":
app.add_request_header("server", "robyn")
current_file_path = pathlib.Path(__file__).parent.resolve()
Expand Down
10 changes: 10 additions & 0 deletions integration_tests/test_status_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ def test_307_get_request(session):
def test_int_status_code(session):
r = requests.get(f"{BASE_URL}/int_status_code")
assert r.status_code == 202


def test_sync_500_internal_server_error(session):
r = requests.get(f"{BASE_URL}/sync/raise")
assert r.status_code == 500


def test_async_500_internal_server_error(session):
r = requests.get(f"{BASE_URL}/async/raise")
assert r.status_code == 500
2 changes: 1 addition & 1 deletion src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub async fn execute_http_function(request: &Request, function: FunctionInfo) ->
})
} else {
Python::with_gil(|py| -> Result<Response> {
let output = get_function_output(&function, py, request).unwrap();
let output = get_function_output(&function, py, request)?;
output.extract().context("Failed to get route response")
})
}
Expand Down