src/docs/markdown/caddyfile/directives/error.md
Triggers an error in the HTTP handler chain, with an optional message and recommended HTTP status code.
This handler does not write a response. Instead, it's meant to be paired with the handle_errors directive to invoke your custom error handling logic.
error [<matcher>] <status>|<message> [<status>] {
message <text>
}
500.To clarify, the first non-matcher argument can be either a 3-digit status code, or an error message string. If it is an error message, the next argument can be the status code.
Trigger an error on certain request paths, and use handle_errors to write a response:
example.com {
root /srv
# Trigger errors for certain paths
error /private* "Unauthorized" 403
error /hidden* "Not found" 404
# Handle the error by serving an HTML page
handle_errors {
rewrite /{err.status_code}.html
file_server
}
file_server
}