mirror of
https://github.com/openshift/image-registry.git
synced 2026-02-05 18:45:15 +01:00
* Internal modules return only their own errors. All downstream errors are converted. In this case, the module needs to check only N-1 level errors. * Do not convert errors from internal functions. They must return the correct errors. * When converting an error with loss of context, it is necessary to write the previous error to the log. Signed-off-by: Gladkov Alexey <agladkov@redhat.com>
42 lines
861 B
Go
42 lines
861 B
Go
package errors
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
errcode "github.com/docker/distribution/registry/api/errcode"
|
|
)
|
|
|
|
const errGroup = "openshift"
|
|
|
|
var (
|
|
ErrorCodePullthroughManifest = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
Value: "OPENSHIFT_PULLTHROUGH_MANIFEST",
|
|
Message: "unable to pull manifest from %s: %v",
|
|
// We have to use an error code within the range [400, 499].
|
|
// Otherwise the error message with not be shown by the client.
|
|
HTTPStatusCode: http.StatusNotFound,
|
|
})
|
|
)
|
|
|
|
// Error provides a wrapper around error.
|
|
type Error struct {
|
|
Code string
|
|
Message string
|
|
Err error
|
|
}
|
|
|
|
var _ error = Error{}
|
|
|
|
func (e Error) Error() string {
|
|
return fmt.Sprintf("%s: %s: %s", e.Code, e.Message, e.Err.Error())
|
|
}
|
|
|
|
func NewError(code, msg string, err error) *Error {
|
|
return &Error{
|
|
Code: code,
|
|
Message: msg,
|
|
Err: err,
|
|
}
|
|
}
|