-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add
error
caddyfile directive (#143)
Docs for the new directive in caddyserver/caddy#4034. Also adding a bit in `handle_errors` mentioning that `reverse_proxy` doesn't trigger errors when a response has an "error" HTTP status; not sure how to word this clearly, cause `reverse_proxy` still can trigger errors if there's no upstream or whatever. We should probably add examples for that later, and augment this paragraph to mention `handle_response` once that's merged (caddyserver/caddy#4021)
- Loading branch information
1 parent
b0324a9
commit 9dc0156
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: error (Caddyfile directive) | ||
--- | ||
|
||
# error | ||
|
||
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`](handle_errors) directive to invoke your custom error handling logic. | ||
|
||
|
||
## Syntax | ||
|
||
```caddy-d | ||
error [<matcher>] <status>|<message> [<status>] { | ||
message <text> | ||
} | ||
``` | ||
|
||
- **<status>** is the HTTP status code to write. Default is `500`. | ||
- **<message>** is the error message. Default is no error message. | ||
- **message** is an alternate way to provide an error message; convenient if it is multiple lines. | ||
|
||
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. | ||
|
||
## Examples | ||
|
||
Trigger an error on certain request paths, and use [`handle_errors`](handle_errors) to write a response: | ||
|
||
```caddy | ||
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 * /{http.error.status_code}.html | ||
file_server | ||
} | ||
file_server | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters