diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-04-11 20:42:55 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-04-11 20:42:55 -0600 |
commit | 545f28008e0175491af030f8689cab2112fda9ed (patch) | |
tree | dc0d769486b8e05da7c67219292e9c0f95bb7f0b /modules/caddyhttp/caddylog | |
parent | d42529348fac36f256d4e180ba1c2049f65646c1 (diff) |
Begin implementing error handling and re-handling
Diffstat (limited to 'modules/caddyhttp/caddylog')
-rw-r--r-- | modules/caddyhttp/caddylog/log.go | 12 |
1 files changed, 12 insertions, 0 deletions
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 } |