2018-06-10 11:11:41 +02:00
package models
import "fmt"
// =====================
// User Operation Errors
// =====================
// ErrUsernameExists represents a "UsernameAlreadyExists" kind of error.
type ErrUsernameExists struct {
UserID int64
Username string
}
// IsErrUsernameExists checks if an error is a ErrUsernameExists.
func IsErrUsernameExists ( err error ) bool {
_ , ok := err . ( ErrUsernameExists )
return ok
}
func ( err ErrUsernameExists ) Error ( ) string {
return fmt . Sprintf ( "a user with this username does already exist [user id: %d, username: %s]" , err . UserID , err . Username )
}
// ErrUserEmailExists represents a "UserEmailExists" kind of error.
type ErrUserEmailExists struct {
UserID int64
Email string
}
// IsErrUserEmailExists checks if an error is a ErrUserEmailExists.
func IsErrUserEmailExists ( err error ) bool {
_ , ok := err . ( ErrUserEmailExists )
return ok
}
func ( err ErrUserEmailExists ) Error ( ) string {
return fmt . Sprintf ( "a user with this email does already exist [user id: %d, email: %s]" , err . UserID , err . Email )
}
// ErrNoUsername represents a "UsernameAlreadyExists" kind of error.
type ErrNoUsername struct {
UserID int64
}
// IsErrNoUsername checks if an error is a ErrUsernameExists.
func IsErrNoUsername ( err error ) bool {
_ , ok := err . ( ErrNoUsername )
return ok
}
func ( err ErrNoUsername ) Error ( ) string {
return fmt . Sprintf ( "you need to specify a username [user id: %d]" , err . UserID )
}
// ErrNoUsernamePassword represents a "NoUsernamePassword" kind of error.
type ErrNoUsernamePassword struct { }
// IsErrNoUsernamePassword checks if an error is a ErrNoUsernamePassword.
func IsErrNoUsernamePassword ( err error ) bool {
_ , ok := err . ( ErrNoUsernamePassword )
return ok
}
func ( err ErrNoUsernamePassword ) Error ( ) string {
return fmt . Sprintf ( "you need to specify a username and a password" )
}
// ErrUserDoesNotExist represents a "UserDoesNotExist" kind of error.
type ErrUserDoesNotExist struct {
UserID int64
}
// IsErrUserDoesNotExist checks if an error is a ErrUserDoesNotExist.
func IsErrUserDoesNotExist ( err error ) bool {
_ , ok := err . ( ErrUserDoesNotExist )
return ok
}
func ( err ErrUserDoesNotExist ) Error ( ) string {
return fmt . Sprintf ( "this user does not exist [user id: %d]" , err . UserID )
}
// ErrCouldNotGetUserID represents a "ErrCouldNotGetUserID" kind of error.
type ErrCouldNotGetUserID struct { }
// IsErrCouldNotGetUserID checks if an error is a ErrCouldNotGetUserID.
func IsErrCouldNotGetUserID ( err error ) bool {
_ , ok := err . ( ErrCouldNotGetUserID )
return ok
}
func ( err ErrCouldNotGetUserID ) Error ( ) string {
return fmt . Sprintf ( "could not get user ID" )
}
// ErrCannotDeleteLastUser represents a "ErrCannotDeleteLastUser" kind of error.
type ErrCannotDeleteLastUser struct { }
// IsErrCannotDeleteLastUser checks if an error is a ErrCannotDeleteLastUser.
func IsErrCannotDeleteLastUser ( err error ) bool {
_ , ok := err . ( ErrCannotDeleteLastUser )
return ok
}
func ( err ErrCannotDeleteLastUser ) Error ( ) string {
return fmt . Sprintf ( "cannot delete last user" )
}
// ===================
// Empty things errors
// ===================
// ErrIDCannotBeZero represents a "IDCannotBeZero" kind of error. Used if an ID (of something, not defined) is 0 where it should not.
type ErrIDCannotBeZero struct { }
// IsErrIDCannotBeZero checks if an error is a ErrIDCannotBeZero.
func IsErrIDCannotBeZero ( err error ) bool {
_ , ok := err . ( ErrIDCannotBeZero )
return ok
}
func ( err ErrIDCannotBeZero ) Error ( ) string {
return fmt . Sprintf ( "ID cannot be 0" )
2018-06-10 14:14:10 +02:00
}
// ===========
// List errors
// ===========
// ErrListDoesNotExist represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
2018-06-10 14:22:37 +02:00
type ErrListDoesNotExist struct {
2018-06-10 14:14:10 +02:00
ID int64
}
// IsErrListDoesNotExist checks if an error is a ErrListDoesNotExist.
func IsErrListDoesNotExist ( err error ) bool {
_ , ok := err . ( ErrListDoesNotExist )
return ok
}
func ( err ErrListDoesNotExist ) Error ( ) string {
return fmt . Sprintf ( "List does not exist [ID: %d]" , err . ID )
2018-06-10 14:22:37 +02:00
}
2018-06-10 19:49:40 +02:00
2018-07-09 23:17:19 +02:00
// ErrNeedToBeListAdmin represents an error, where the user is not the owner of that list (used i.e. when deleting a list)
type ErrNeedToBeListAdmin struct {
2018-06-12 18:46:59 +02:00
ListID int64
UserID int64
}
2018-07-10 14:02:23 +02:00
// IsErrNeedToBeListAdmin checks if an error is a ErrListDoesNotExist.
2018-07-09 23:17:19 +02:00
func IsErrNeedToBeListAdmin ( err error ) bool {
_ , ok := err . ( ErrNeedToBeListAdmin )
2018-06-12 18:46:59 +02:00
return ok
}
2018-07-09 23:17:19 +02:00
func ( err ErrNeedToBeListAdmin ) Error ( ) string {
2018-06-12 18:46:59 +02:00
return fmt . Sprintf ( "You need to be list owner to do that [ListID: %d, UserID: %d]" , err . ListID , err . UserID )
}
// ================
// List item errors
// ================
2018-06-10 19:49:40 +02:00
// ErrListItemCannotBeEmpty represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
type ErrListItemCannotBeEmpty struct { }
// IsErrListItemCannotBeEmpty checks if an error is a ErrListDoesNotExist.
func IsErrListItemCannotBeEmpty ( err error ) bool {
_ , ok := err . ( ErrListItemCannotBeEmpty )
return ok
}
func ( err ErrListItemCannotBeEmpty ) Error ( ) string {
return fmt . Sprintf ( "List item text cannot be empty." )
}
2018-06-12 18:35:36 +02:00
2018-07-10 14:02:23 +02:00
// ErrListItemDoesNotExist represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
2018-06-13 13:45:22 +02:00
type ErrListItemDoesNotExist struct {
2018-06-12 18:35:36 +02:00
ID int64
}
2018-07-10 14:02:23 +02:00
// IsErrListItemDoesNotExist checks if an error is a ErrListDoesNotExist.
2018-06-12 18:35:36 +02:00
func IsErrListItemDoesNotExist ( err error ) bool {
_ , ok := err . ( ErrListItemDoesNotExist )
return ok
}
func ( err ErrListItemDoesNotExist ) Error ( ) string {
return fmt . Sprintf ( "List item does not exist. [ID: %d]" , err . ID )
}
2018-06-12 18:49:56 +02:00
// ErrNeedToBeItemOwner represents an error, where the user is not the owner of that item (used i.e. when deleting a list)
type ErrNeedToBeItemOwner struct {
ItemID int64
UserID int64
}
// IsErrNeedToBeItemOwner checks if an error is a ErrNeedToBeItemOwner.
func IsErrNeedToBeItemOwner ( err error ) bool {
_ , ok := err . ( ErrNeedToBeItemOwner )
return ok
}
func ( err ErrNeedToBeItemOwner ) Error ( ) string {
return fmt . Sprintf ( "You need to be item owner to do that [ItemID: %d, UserID: %d]" , err . ItemID , err . UserID )
2018-06-13 13:45:22 +02:00
}
2018-07-02 08:40:24 +02:00
// =================
// Namespace errors
// =================
// ErrNamespaceDoesNotExist represents a "ErrNamespaceDoesNotExist" kind of error. Used if the namespace does not exist.
type ErrNamespaceDoesNotExist struct {
ID int64
}
// IsErrNamespaceDoesNotExist checks if an error is a ErrNamespaceDoesNotExist.
func IsErrNamespaceDoesNotExist ( err error ) bool {
_ , ok := err . ( ErrNamespaceDoesNotExist )
return ok
}
func ( err ErrNamespaceDoesNotExist ) Error ( ) string {
return fmt . Sprintf ( "Namespace does not exist [ID: %d]" , err . ID )
}
// ErrNeedToBeNamespaceOwner represents an error, where the user is not the owner of that namespace (used i.e. when deleting a namespace)
type ErrNeedToBeNamespaceOwner struct {
NamespaceID int64
2018-07-02 08:54:44 +02:00
UserID int64
2018-07-02 08:40:24 +02:00
}
2018-07-10 14:02:23 +02:00
// IsErrNeedToBeNamespaceOwner checks if an error is a ErrNamespaceDoesNotExist.
2018-07-02 08:40:24 +02:00
func IsErrNeedToBeNamespaceOwner ( err error ) bool {
_ , ok := err . ( ErrNeedToBeNamespaceOwner )
return ok
}
func ( err ErrNeedToBeNamespaceOwner ) Error ( ) string {
return fmt . Sprintf ( "You need to be namespace owner to do that [NamespaceID: %d, UserID: %d]" , err . NamespaceID , err . UserID )
2018-07-02 08:54:44 +02:00
}
2018-07-04 08:56:52 +02:00
// ErrUserDoesNotHaveAccessToNamespace represents an error, where the user is not the owner of that namespace (used i.e. when deleting a namespace)
type ErrUserDoesNotHaveAccessToNamespace struct {
NamespaceID int64
UserID int64
}
// IsErrUserDoesNotHaveAccessToNamespace checks if an error is a ErrNamespaceDoesNotExist.
func IsErrUserDoesNotHaveAccessToNamespace ( err error ) bool {
_ , ok := err . ( ErrUserDoesNotHaveAccessToNamespace )
return ok
}
func ( err ErrUserDoesNotHaveAccessToNamespace ) Error ( ) string {
2018-07-05 08:52:05 +02:00
return fmt . Sprintf ( "You need to have access to this namespace to do that [NamespaceID: %d, UserID: %d]" , err . NamespaceID , err . UserID )
2018-07-04 08:56:52 +02:00
}
2018-07-04 19:21:04 +02:00
// ErrUserNeedsToBeNamespaceAdmin represents an error, where the user is not the owner of that namespace (used i.e. when deleting a namespace)
type ErrUserNeedsToBeNamespaceAdmin struct {
NamespaceID int64
UserID int64
}
// IsErrUserNeedsToBeNamespaceAdmin checks if an error is a ErrNamespaceDoesNotExist.
func IsErrUserNeedsToBeNamespaceAdmin ( err error ) bool {
_ , ok := err . ( ErrUserNeedsToBeNamespaceAdmin )
return ok
}
2018-07-04 08:56:52 +02:00
2018-07-04 19:21:04 +02:00
func ( err ErrUserNeedsToBeNamespaceAdmin ) Error ( ) string {
2018-07-05 08:52:05 +02:00
return fmt . Sprintf ( "You need to be namespace admin to do that [NamespaceID: %d, UserID: %d]" , err . NamespaceID , err . UserID )
}
// ErrUserDoesNotHaveWriteAccessToNamespace represents an error, where the user is not the owner of that namespace (used i.e. when deleting a namespace)
type ErrUserDoesNotHaveWriteAccessToNamespace struct {
NamespaceID int64
UserID int64
}
// IsErrUserDoesNotHaveWriteAccessToNamespace checks if an error is a ErrNamespaceDoesNotExist.
func IsErrUserDoesNotHaveWriteAccessToNamespace ( err error ) bool {
_ , ok := err . ( ErrUserDoesNotHaveWriteAccessToNamespace )
return ok
}
func ( err ErrUserDoesNotHaveWriteAccessToNamespace ) Error ( ) string {
return fmt . Sprintf ( "You need to have write access to this namespace to do that [NamespaceID: %d, UserID: %d]" , err . NamespaceID , err . UserID )
2018-07-04 19:21:04 +02:00
}