2022-03-30 04:42:47 -04:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-03-30 04:42:47 -04:00
|
|
|
|
|
|
|
|
package container
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#error-codes
|
|
|
|
|
var (
|
2026-03-06 12:56:49 -05:00
|
|
|
ErrBlobUnknown = &NamedError{Code: "BLOB_UNKNOWN", StatusCode: http.StatusNotFound}
|
|
|
|
|
ErrBlobUploadInvalid = &NamedError{Code: "BLOB_UPLOAD_INVALID", StatusCode: http.StatusBadRequest}
|
|
|
|
|
ErrBlobUploadUnknown = &NamedError{Code: "BLOB_UPLOAD_UNKNOWN", StatusCode: http.StatusNotFound}
|
|
|
|
|
ErrDigestInvalid = &NamedError{Code: "DIGEST_INVALID", StatusCode: http.StatusBadRequest}
|
|
|
|
|
ErrManifestBlobUnknown = &NamedError{Code: "MANIFEST_BLOB_UNKNOWN", StatusCode: http.StatusNotFound}
|
|
|
|
|
ErrManifestInvalid = &NamedError{Code: "MANIFEST_INVALID", StatusCode: http.StatusBadRequest}
|
|
|
|
|
ErrManifestUnknown = &NamedError{Code: "MANIFEST_UNKNOWN", StatusCode: http.StatusNotFound}
|
|
|
|
|
ErrNameInvalid = &NamedError{Code: "NAME_INVALID", StatusCode: http.StatusBadRequest}
|
|
|
|
|
ErrNameUnknown = &NamedError{Code: "NAME_UNKNOWN", StatusCode: http.StatusNotFound}
|
|
|
|
|
ErrSizeInvalid = &NamedError{Code: "SIZE_INVALID", StatusCode: http.StatusBadRequest}
|
|
|
|
|
ErrUnauthorized = &NamedError{Code: "UNAUTHORIZED", StatusCode: http.StatusUnauthorized}
|
|
|
|
|
ErrUnsupported = &NamedError{Code: "UNSUPPORTED", StatusCode: http.StatusNotImplemented}
|
2022-03-30 04:42:47 -04:00
|
|
|
)
|
|
|
|
|
|
2026-03-06 12:56:49 -05:00
|
|
|
type NamedError struct {
|
2022-03-30 04:42:47 -04:00
|
|
|
Code string
|
|
|
|
|
StatusCode int
|
|
|
|
|
Message string
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 12:56:49 -05:00
|
|
|
func (e *NamedError) Error() string {
|
2022-03-30 04:42:47 -04:00
|
|
|
return e.Message
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithMessage creates a new instance of the error with a different message
|
2026-03-06 12:56:49 -05:00
|
|
|
func (e *NamedError) WithMessage(message string) *NamedError {
|
|
|
|
|
return &NamedError{
|
2022-03-30 04:42:47 -04:00
|
|
|
Code: e.Code,
|
|
|
|
|
StatusCode: e.StatusCode,
|
|
|
|
|
Message: message,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithStatusCode creates a new instance of the error with a different status code
|
2026-03-06 12:56:49 -05:00
|
|
|
func (e *NamedError) WithStatusCode(statusCode int) *NamedError {
|
|
|
|
|
return &NamedError{
|
2022-03-30 04:42:47 -04:00
|
|
|
Code: e.Code,
|
|
|
|
|
StatusCode: statusCode,
|
|
|
|
|
Message: e.Message,
|
|
|
|
|
}
|
|
|
|
|
}
|