mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 18:44:54 +08:00

* Unified Storage: Return an already exists error When inserting a resource that already exists (i.e. race condition), we can safely catch UNIQUE constraint violations and transform them into a `k8s.io/apimachinery/pkg/api/errors` error that stands the test of `errors.IsAlreadyExists`. * feat: clarify existing conflict error * chore: make update-workspace * feat: make new package for backend error * fix: assign dependency owner * feat: use dialect for checking error type * chore: go generate * revert: to 5af369166d6
22 lines
602 B
Go
22 lines
602 B
Go
package backend
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
// Errors that may be returned by the storage backend, to be converted by the resource layer.
|
|
// These are defined here to let all storage backends use the same error types without depending on one another.
|
|
var (
|
|
ErrResourceAlreadyExists error = &apierrors.StatusError{
|
|
ErrStatus: metav1.Status{
|
|
Status: metav1.StatusFailure,
|
|
Reason: metav1.StatusReasonAlreadyExists,
|
|
Message: "the resource already exists",
|
|
Code: http.StatusConflict,
|
|
},
|
|
}
|
|
)
|