Fail unresolved unit renders with HTTP 500
This commit is contained in:
@@ -18,6 +18,8 @@ Calls another UCE file and executes its `RENDER(Request& context)` function.
|
||||
|
||||
If `context` is omitted, the current active request context is used.
|
||||
|
||||
Calling a missing unit or render handler is a server error and sets HTTP status 500. If a unit is intentionally optional, inspect it with `unit_info()` before calling `unit_render()`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
||||
|
||||
@@ -329,6 +329,11 @@ void cli_run_site_suite(bool skip_local_service_pages = false)
|
||||
|
||||
void cli_run_security_smoke()
|
||||
{
|
||||
CliHttpResponse missing_unit = cli_frontend("/tests/unit_failure.uce");
|
||||
cli_test_case("uce_unit_failure:unit_render missing target is HTTP 500",
|
||||
missing_unit.status == 500 && cli_contains(missing_unit.body, "unit not found: does-not-exist.uce"),
|
||||
"status=" + std::to_string(missing_unit.status) + " body=" + cli_truncate(missing_unit.body));
|
||||
|
||||
CliHttpResponse missing_component = cli_frontend("/tests/component_failure.uce");
|
||||
cli_test_case("uce_component_failure:component_render missing target is HTTP 500",
|
||||
missing_component.status == 500 && cli_contains(missing_component.body, "component not found: components/does-not-exist"),
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
RENDER(Request& context)
|
||||
{
|
||||
unit_render("does-not-exist.uce", context);
|
||||
}
|
||||
@@ -727,6 +727,7 @@ void unit_render(String file_name, Request& request)
|
||||
s32 slot = wasm_resolve_target(unit_name, handler, &resolved);
|
||||
if(!slot)
|
||||
{
|
||||
request.set_status(500, "Internal Server Error");
|
||||
print(component_error_banner("unit not found: " + trim(file_name)));
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user