Merge "httputil: add ForbiddenError and RequestEntityTooLargeError"

This commit is contained in:
Brad Fitzpatrick 2011-06-15 08:37:18 -07:00 committed by Gerrit Code Review
commit 6b77e2dd57
1 changed files with 14 additions and 2 deletions

View File

@ -30,12 +30,24 @@ func ErrorRouting(conn http.ResponseWriter, req *http.Request) {
log.Printf("Internal routing error on %q", req.URL.Path)
}
func BadRequestError(conn http.ResponseWriter, errorMessage string) {
func BadRequestError(conn http.ResponseWriter, errorMessage string, args ...interface{}) {
conn.WriteHeader(http.StatusBadRequest)
log.Printf("Bad request: %s", errorMessage)
log.Printf("Bad request: %s", fmt.Sprintf(errorMessage, args...))
fmt.Fprintf(conn, "%s\n", errorMessage)
}
func ForbiddenError(conn http.ResponseWriter, errorMessage string, args ...interface{}) {
conn.WriteHeader(http.StatusForbidden)
log.Printf("Forbidden: %s", fmt.Sprintf(errorMessage, args...))
fmt.Fprintf(conn, "<h1>Forbidden</h1>")
}
func RequestEntityTooLargeError(conn http.ResponseWriter, errorMessage string, args ...interface{}) {
conn.WriteHeader(http.StatusForbidden)
log.Printf("Request entity is too large: %s", fmt.Sprintf(errorMessage, args...))
fmt.Fprintf(conn, "<h1>Request entity is too large</h1>")
}
func ServerError(conn http.ResponseWriter, err os.Error) {
conn.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(conn, "Server error: %s\n", err)