errorResponse(request, error_message, status, use_heading):
→ hwebserver.Response
request
The Request
object passed to the URL handler or API function.
(The function checks the request to see if the client wants a JSON response. If the client provided an Accept: application/json, */*
header, this returns the JSON response {"error": error_message}
, and error_message
may be any JSON-encodable value.)
error_message
Error message to display to the user.
(This can be any JSON-encodable value if you know the response will be JSON rather than HTML.)
use_heading
If the response is an HTML page (instead of JSON), automatically wrap the error_message
in an <h1>
element.
import hou import hwebserver @hwebserver.urlHandler("/node/info/", is_prefix=True) def node_info(request): path = request.path() assert path.startswith("/node/info") node_path = path[10:] node = hou.node(node_path) if node is None: return hwebserver.errorResponse(request, "Resource not found", 404) # ...
See also |