From 545f28008e0175491af030f8689cab2112fda9ed Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 11 Apr 2019 20:42:55 -0600 Subject: Begin implementing error handling and re-handling --- modules/caddyhttp/caddylog/log.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'modules/caddyhttp/caddylog') diff --git a/modules/caddyhttp/caddylog/log.go b/modules/caddyhttp/caddylog/log.go index f7bc9fd..dc940b3 100644 --- a/modules/caddyhttp/caddylog/log.go +++ b/modules/caddyhttp/caddylog/log.go @@ -13,6 +13,7 @@ func init() { caddy2.RegisterModule(caddy2.Module{ Name: "http.middleware.log", New: func() (interface{}, error) { return new(Log), nil }, + // TODO: Examples of OnLoad and OnUnload. OnLoad: func(instances []interface{}, priorState interface{}) (interface{}, error) { var counter int if priorState != nil { @@ -42,6 +43,17 @@ type Log struct { func (l *Log) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error { start := time.Now() + // TODO: An example of returning errors + // return caddyhttp.Error(http.StatusBadRequest, fmt.Errorf("this is a basic error")) + // return caddyhttp.Error(http.StatusBadGateway, caddyhttp.HandlerError{ + // Err: fmt.Errorf("this is a detailed error"), + // Message: "We had trouble doing the thing.", + // Recommendations: []string{ + // "Try reconnecting the gizbop.", + // "Turn off the Internet.", + // }, + // }) + if err := next.ServeHTTP(w, r); err != nil { return err } -- cgit v1.2.3