1
0
mirror of https://github.com/openshift/image-registry.git synced 2026-02-05 09:45:55 +01:00
Files
image-registry/pkg/errors/handle.go
Flavian Missi f9d93c44be pkg,test: import distribution/distribution/v3
instead of the deprecated docker/distribution
2023-06-19 12:06:47 +02:00

26 lines
653 B
Go

package errors
import (
"context"
dcontext "github.com/distribution/distribution/v3/context"
errcode "github.com/distribution/distribution/v3/registry/api/errcode"
)
type errMessageKey struct{}
func (errMessageKey) String() string { return "err.message" }
type errDetailKey struct{}
func (errDetailKey) String() string { return "err.detail" }
func Handle(ctx context.Context, message string, err error) {
ctx = context.WithValue(ctx, errMessageKey{}, err)
switch err := err.(type) {
case errcode.Error:
ctx = context.WithValue(ctx, errDetailKey{}, err.Detail)
}
dcontext.GetLogger(ctx, errMessageKey{}, errDetailKey{}).Error(message)
}