service backend
This commit is contained in:
65
api/pkg/merrors/errors.go
Normal file
65
api/pkg/merrors/errors.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package merrors
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
var ErrNotImplemented = errors.New("notImplemented")
|
||||
|
||||
func NotImplemented(msg string) error {
|
||||
return fmt.Errorf("%w: %s", ErrNotImplemented, msg)
|
||||
}
|
||||
|
||||
var ErrNoData = errors.New("noData")
|
||||
|
||||
func NoData(msg string) error {
|
||||
return fmt.Errorf("%w: %s", ErrNoData, msg)
|
||||
}
|
||||
|
||||
var ErrInternal = errors.New("internal")
|
||||
|
||||
func Internal(msg string) error {
|
||||
return fmt.Errorf("%w: %s", ErrInternal, msg)
|
||||
}
|
||||
|
||||
var ErrInvalidArg = errors.New("invalidArgError")
|
||||
|
||||
func InvalidArgument(msg string) error {
|
||||
return fmt.Errorf("%w: %s", ErrInvalidArg, msg)
|
||||
}
|
||||
|
||||
var ErrDataConflict = errors.New("DataConflict")
|
||||
|
||||
func DataConflict(msg string) error {
|
||||
return fmt.Errorf("%w: %s", ErrDataConflict, msg)
|
||||
}
|
||||
|
||||
var ErrAccessDenied = errors.New("accessDenied")
|
||||
|
||||
func AccessDenied(object, action string, objectRef primitive.ObjectID) error {
|
||||
if objectRef != primitive.NilObjectID {
|
||||
return fmt.Errorf("%w: cannot %s object of type '%s' with ID '%s'", ErrAccessDenied, action, object, objectRef.Hex())
|
||||
}
|
||||
return fmt.Errorf("%w: cannot %s object of type '%s'", ErrAccessDenied, action, object)
|
||||
}
|
||||
|
||||
var ErrInvalidDataType = errors.New("invalidDataType")
|
||||
|
||||
func InvalidDataType(msg string) error {
|
||||
return fmt.Errorf("%w: %s", ErrDataConflict, msg)
|
||||
}
|
||||
|
||||
var ErrUnauthorized = errors.New("unathorized")
|
||||
|
||||
func Unauthorized(msg string) error {
|
||||
return fmt.Errorf("%w: %s", ErrDataConflict, msg)
|
||||
}
|
||||
|
||||
var ErrNoMessagingTopic = errors.New("messagingTopicError")
|
||||
|
||||
func NoMessagingTopic(topic string) error {
|
||||
return fmt.Errorf("%w: messaging topic '%s' not found", ErrNoMessagingTopic, topic)
|
||||
}
|
||||
Reference in New Issue
Block a user