Keep API not-found and 401 responses usable behind Ingress and in the Web UI.

Return native JSON with the missing id in the message, clear stale sessions on
401, and document ingress-nginx annotations so branded HTML 404/405 pages do
not rewrite simulator bodies.
This commit is contained in:
2026-07-22 06:52:35 +03:00
parent 131e2e63d2
commit e8b08526d1
13 changed files with 260 additions and 62 deletions
+24 -2
View File
@@ -41,16 +41,38 @@ def unauthenticated(message: str = "Authentication required") -> VsphereError:
)
def not_found(message: str = "Not found") -> VsphereError:
def not_found(message: str = "Not found", *, args: list[Any] | None = None) -> VsphereError:
return VsphereError(
404,
error_type="not_found",
messages=[
{"default_message": message, "id": "com.vmware.vapi.std.errors.not_found", "args": []}
{
"default_message": message,
"id": "com.vmware.vapi.std.errors.not_found",
"args": list(args or []),
}
],
)
def no_such(resource: str, resource_id: str) -> VsphereError:
"""Native not-found with the missing id in the message (Ingress-friendly JSON)."""
message = f"No such {resource} ('{resource_id}')"
return VsphereError(
404,
error_type="not_found",
messages=[
{
"default_message": message,
"id": "com.vmware.vapi.std.errors.not_found",
"args": [resource_id],
}
],
data={resource: message},
)
def already_exists(message: str = "Already exists") -> VsphereError:
return VsphereError(
400,