$overlay{_template.html#body} $begin{content}
To return an HTTP Error as response the minimum required is to set the status with the right error code. The QP Publisher offers a convenient shortcut generic method, respond(title, *content, **kwargs), to quickly do a response, from anywhere within the request processing, pre-empting the processing of the current hit.
An error response may therefore simply be a call to this method, e.g.: respond('Unauthorized', 'Unauthorized', status=401). For 401 and 404 errors, dedicated methods wrap the publisher.respond() method to make returning these frequently occuring error responses trivial.
Note that QP considers that if an export returns a None value then the exported resource is Not Found.
${html.ul([ html.href('not-authorized', 'get_publisher().unauthorized() -> 401, Unauthorized'), html.href('non-existant', 'get_publisher().not_found() -> 404, Not Found'), html.href('none', 'export returns a None value -> 404, Not Found'), ])}Note that even for an error response, Gizmo(QP) takes care to generate a fully formatted page as per the site template specified for error pages, with a navigation menu that corresponds to both the user's privileges as well as the page's hierarchical location.
$end{content}