2020-04-20 16:55:23 +00:00
|
|
|
package dbrp
|
|
|
|
|
|
|
|
import (
|
2021-01-07 17:08:06 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
|
|
|
|
2020-04-20 16:55:23 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrDBRPNotFound is used when the specified DBRP cannot be found.
|
2021-03-30 18:10:02 +00:00
|
|
|
ErrDBRPNotFound = &errors.Error{
|
|
|
|
Code: errors.ENotFound,
|
2020-04-20 16:55:23 +00:00
|
|
|
Msg: "unable to find DBRP",
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrNotUniqueID is used when the ID of the DBRP is not unique.
|
2021-03-30 18:10:02 +00:00
|
|
|
ErrNotUniqueID = &errors.Error{
|
|
|
|
Code: errors.EConflict,
|
2020-04-20 16:55:23 +00:00
|
|
|
Msg: "ID already exists",
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrFailureGeneratingID occurs ony when the random number generator
|
|
|
|
// cannot generate an ID in MaxIDGenerationN times.
|
2021-03-30 18:10:02 +00:00
|
|
|
ErrFailureGeneratingID = &errors.Error{
|
|
|
|
Code: errors.EInternal,
|
2020-04-20 16:55:23 +00:00
|
|
|
Msg: "unable to generate valid id",
|
|
|
|
}
|
2021-01-07 17:08:06 +00:00
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
ErrNoOrgProvided = &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2021-01-07 17:08:06 +00:00
|
|
|
Msg: "either 'org' or 'orgID' must be provided",
|
|
|
|
}
|
2020-04-20 16:55:23 +00:00
|
|
|
)
|
|
|
|
|
2021-01-07 17:08:06 +00:00
|
|
|
// ErrOrgNotFound returns a more informative error about a 404 on org name.
|
|
|
|
func ErrOrgNotFound(org string) error {
|
2021-03-30 18:10:02 +00:00
|
|
|
return &errors.Error{
|
|
|
|
Code: errors.ENotFound,
|
2021-01-07 17:08:06 +00:00
|
|
|
Msg: fmt.Sprintf("invalid org %q", org),
|
|
|
|
Err: influxdb.ErrOrgNotFound,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrInvalidOrgID returns a more informative error about a failure
|
|
|
|
// to decode an organization ID.
|
|
|
|
func ErrInvalidOrgID(id string, err error) error {
|
2021-03-30 18:10:02 +00:00
|
|
|
return &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2021-01-07 17:08:06 +00:00
|
|
|
Msg: fmt.Sprintf("invalid org ID %q", id),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrInvalidBucketID returns a more informative error about a failure
|
|
|
|
// to decode a bucket ID.
|
|
|
|
func ErrInvalidBucketID(id string, err error) error {
|
2021-03-30 18:10:02 +00:00
|
|
|
return &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2021-01-07 17:08:06 +00:00
|
|
|
Msg: fmt.Sprintf("invalid bucket ID %q", id),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrInvalidDBRPID is used when the ID of the DBRP cannot be encoded.
|
|
|
|
func ErrInvalidDBRPID(id string, err error) error {
|
2021-03-30 18:10:02 +00:00
|
|
|
return &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2021-01-07 17:08:06 +00:00
|
|
|
Msg: fmt.Sprintf("invalid DBRP ID %q", id),
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 16:55:23 +00:00
|
|
|
// ErrInvalidDBRP is used when a service was provided an invalid DBRP.
|
2021-03-30 18:10:02 +00:00
|
|
|
func ErrInvalidDBRP(err error) *errors.Error {
|
|
|
|
return &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2020-04-20 16:55:23 +00:00
|
|
|
Msg: "DBRP provided is invalid",
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrInternalService is used when the error comes from an internal system.
|
2021-03-30 18:10:02 +00:00
|
|
|
func ErrInternalService(err error) *errors.Error {
|
|
|
|
return &errors.Error{
|
|
|
|
Code: errors.EInternal,
|
2020-04-20 16:55:23 +00:00
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrDBRPAlreadyExists is used when there is a conflict in creating a new DBRP.
|
2021-03-30 18:10:02 +00:00
|
|
|
func ErrDBRPAlreadyExists(msg string) *errors.Error {
|
2020-04-20 16:55:23 +00:00
|
|
|
if msg == "" {
|
|
|
|
msg = "DBRP already exists"
|
|
|
|
}
|
2021-03-30 18:10:02 +00:00
|
|
|
return &errors.Error{
|
|
|
|
Code: errors.EConflict,
|
2020-04-20 16:55:23 +00:00
|
|
|
Msg: msg,
|
|
|
|
}
|
|
|
|
}
|