PublicShow sourcehttp_exception.pl -- Map Prolog exceptions to HTTP errors

This module maps exceptions from various parts of the HTTP libraries as well as exceptions from user handler predicates into meaningful HTTP error codes such as 4XX and 5XX codes. For example, existence errors on http locations are mapped to 404 while out-of-stack is mapped to 503.

This library provides one hook: http:bad_request_error/2 can be extended to map exceptions into 400 bad request responses.

See also
- http_header.pl, http_wrapper.pl
Sourcemap_exception_to_http_status(+Exception, -Reply, -HdrExtra, -Context)
Map certain defined exceptions to special reply codes. The http(not_modified) provides backward compatibility to http_reply(not_modified).
Sourcein_or_exclude_backtrace(+ErrorIn, -ErrorOut)
Remove the stacktrace from the exception, unless setting http:client_backtrace is true.
Sourcehttp:bad_request_error(+Formal, -ContextTemplate) is semidet[multifile]
If an exception of the term error(Formal, context(Stack, Context)) is caught and subsumes_term(ContextTemplate, Context) is true, translate the exception into an HTTP 400 exception. If the exception contains a stack-trace, this is stripped from the response.

The idea behind this hook is that applications can raise 400 responses by

  • Throwing a specific (error) exception and adding a rule to this predicate to interpret this as 400.
  • Define rules for error_message//1 to formulate an appropriate message.