Skip to content

Commit

Permalink
unstaged
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas committed Dec 22, 2017
1 parent 297215f commit af5252a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/ory/fosite"
)

var (
Expand All @@ -43,17 +44,25 @@ type stackTracer interface {
}

func LogError(err error, logger log.FieldLogger) {
var debug string
if logger == nil {
logger = log.New()
}

if e, ok := err.(*fosite.RFC6749Error); ok {
debug = e.Debug
} else if e, ok := errors.Cause(err).(*fosite.RFC6749Error); ok {
debug = e.Debug
}

if e, ok := errors.Cause(err).(stackTracer); ok {
logger.WithError(err).Errorln("An error occurred")
logger.WithError(err).WithField("debug", debug).Errorln("An error occurred")
logger.Debugf("Stack trace: %+v", e.StackTrace())
} else if e, ok := err.(stackTracer); ok {
logger.WithError(err).Errorln("An error occurred")
logger.WithError(err).WithField("debug", debug).Errorln("An error occurred")
logger.Debugf("Stack trace: %+v", e.StackTrace())
} else {
logger.WithError(err).Errorln("An error occurred")
logger.WithError(err).WithField("debug", debug).Errorln("An error occurred")
logger.Debugf("Stack trace could not be recovered from error type %s", reflect.TypeOf(err))
}
}

0 comments on commit af5252a

Please sign in to comment.