From fd447c5b540ec0636d705f8d7ca0855e95eec7b8 Mon Sep 17 00:00:00 2001 From: max furman Date: Thu, 25 Mar 2021 16:45:26 -0700 Subject: [PATCH] Fix small nbf->naf bug in db.CreateOrder - still needs unit test --- acme/db/nosql/order.go | 4 +++- acme/errors.go | 10 ++++++++++ api/errors.go | 8 ++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/acme/db/nosql/order.go b/acme/db/nosql/order.go index 8eb578a9..305c43d1 100644 --- a/acme/db/nosql/order.go +++ b/acme/db/nosql/order.go @@ -3,6 +3,7 @@ package nosql import ( "context" "encoding/json" + "fmt" "sync" "time" @@ -91,9 +92,10 @@ func (db *DB) CreateOrder(ctx context.Context, o *acme.Order) error { ExpiresAt: o.ExpiresAt, Identifiers: o.Identifiers, NotBefore: o.NotBefore, - NotAfter: o.NotBefore, + NotAfter: o.NotAfter, AuthorizationIDs: o.AuthorizationIDs, } + fmt.Printf("dbo = %+v\n", dbo) if err := db.save(ctx, o.ID, dbo, nil, "order", orderTable); err != nil { return err } diff --git a/acme/errors.go b/acme/errors.go index c4309599..f4aa17e7 100644 --- a/acme/errors.go +++ b/acme/errors.go @@ -1,6 +1,7 @@ package acme import ( + "encoding/json" "fmt" "github.com/pkg/errors" @@ -337,3 +338,12 @@ func (e *Error) Cause() error { } return e.Err } + +// ToLog implements the EnableLogger interface. +func (e *Error) ToLog() (interface{}, error) { + b, err := json.Marshal(e) + if err != nil { + return nil, WrapErrorISE(err, "error marshaling acme.Error for logging") + } + return string(b), nil +} diff --git a/api/errors.go b/api/errors.go index 460192fc..67c9ba87 100644 --- a/api/errors.go +++ b/api/errors.go @@ -33,11 +33,15 @@ func WriteError(w http.ResponseWriter, err error) { // Write errors in the response writer if rl, ok := w.(logging.ResponseLogger); ok { + logErr := err + if u, ok := err.(*acme.Error); ok { + logErr = u.Err + } rl.WithFields(map[string]interface{}{ - "error": err, + "error": logErr, }) if os.Getenv("STEPDEBUG") == "1" { - if e, ok := err.(errs.StackTracer); ok { + if e, ok := logErr.(errs.StackTracer); ok { rl.WithFields(map[string]interface{}{ "stack-trace": fmt.Sprintf("%+v", e), })