2018-06-10 11:11:41 +02:00
package models
2018-10-06 15:04:14 +02:00
import (
"fmt"
"net/http"
)
// HTTPErrorProcessor is executed when the defined error is thrown, it will make sure the user sees an appropriate error message and http status code
type HTTPErrorProcessor interface {
HTTPError ( ) HTTPError
}
// HTTPError holds informations about an http error
type HTTPError struct {
HTTPCode int ` json:"-" `
Code int ` json:"code" `
Message string ` json:"message" `
}
2018-06-10 11:11:41 +02:00
// =====================
// 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 {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User with that username already exists [user id: %d, username: %s]" , err . UserID , err . Username )
2018-06-10 11:11:41 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrorCodeUsernameExists holds the unique world-error code of this error
const ErrorCodeUsernameExists = 1001
// HTTPError holds the http error description
func ( err ErrUsernameExists ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrorCodeUsernameExists , Message : "A user with this username already exists." }
}
2018-06-10 11:11:41 +02:00
// 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 {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User with that email already exists [user id: %d, email: %s]" , err . UserID , err . Email )
2018-06-10 11:11:41 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrorCodeUserEmailExists holds the unique world-error code of this error
const ErrorCodeUserEmailExists = 1002
// HTTPError holds the http error description
func ( err ErrUserEmailExists ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrorCodeUserEmailExists , Message : "A user with this email address already exists." }
}
2018-06-10 11:11:41 +02:00
// 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 {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "No username and password provided" )
2018-06-10 11:11:41 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeNoUsernamePassword holds the unique world-error code of this error
const ErrCodeNoUsernamePassword = 1004
// HTTPError holds the http error description
func ( err ErrNoUsernamePassword ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeNoUsernamePassword , Message : "Please specify a username and a password." }
}
2018-06-10 11:11:41 +02:00
// 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 {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User does not exist [user id: %d]" , err . UserID )
2018-06-10 11:11:41 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeUserDoesNotExist holds the unique world-error code of this error
const ErrCodeUserDoesNotExist = 1005
// HTTPError holds the http error description
func ( err ErrUserDoesNotExist ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusNotFound , Code : ErrCodeUserDoesNotExist , Message : "The user does not exist." }
}
2018-06-10 11:11:41 +02:00
// 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 {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "Could not get user ID" )
2018-06-10 11:11:41 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeCouldNotGetUserID holds the unique world-error code of this error
const ErrCodeCouldNotGetUserID = 1006
// HTTPError holds the http error description
func ( err ErrCouldNotGetUserID ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeCouldNotGetUserID , Message : "Could not get user id." }
}
2018-10-27 11:33:28 +02:00
// ErrNoPasswordResetToken represents an error where no password reset token exists for that user
type ErrNoPasswordResetToken struct {
UserID int64
}
2018-06-10 11:11:41 +02:00
2018-10-27 11:33:28 +02:00
func ( err ErrNoPasswordResetToken ) Error ( ) string {
return fmt . Sprintf ( "No token to reset a password [UserID: %d]" , err . UserID )
2018-06-10 11:11:41 +02:00
}
2018-10-27 11:33:28 +02:00
// ErrCodeNoPasswordResetToken holds the unique world-error code of this error
const ErrCodeNoPasswordResetToken = 1008
// HTTPError holds the http error description
func ( err ErrNoPasswordResetToken ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeNoPasswordResetToken , Message : "No token to reset a user's password provided." }
2018-06-10 11:11:41 +02:00
}
2018-10-27 11:33:28 +02:00
// ErrInvalidPasswordResetToken is an error where the password reset token is invalid
type ErrInvalidPasswordResetToken struct {
2018-10-27 15:12:15 +02:00
Token string
2018-10-27 11:33:28 +02:00
}
func ( err ErrInvalidPasswordResetToken ) Error ( ) string {
2018-10-27 15:12:15 +02:00
return fmt . Sprintf ( "Invalid token to reset a password [Token: %s]" , err . Token )
2018-10-27 11:33:28 +02:00
}
// ErrCodeInvalidPasswordResetToken holds the unique world-error code of this error
const ErrCodeInvalidPasswordResetToken = 1009
2018-10-06 15:04:14 +02:00
// HTTPError holds the http error description
2018-10-27 11:33:28 +02:00
func ( err ErrInvalidPasswordResetToken ) HTTPError ( ) HTTPError {
2018-10-27 15:12:15 +02:00
return HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeInvalidPasswordResetToken , Message : "Invalid token to reset a user's password." }
2018-10-27 11:33:28 +02:00
}
// IsErrInvalidPasswordResetToken checks if an error is a ErrInvalidPasswordResetToken.
func IsErrInvalidPasswordResetToken ( err error ) bool {
_ , ok := err . ( ErrInvalidPasswordResetToken )
return ok
2018-10-06 15:04:14 +02:00
}
2018-10-27 15:14:55 +02:00
// ErrInvalidEmailConfirmToken is an error where the email confirm token is invalid
type ErrInvalidEmailConfirmToken struct {
Token string
}
func ( err ErrInvalidEmailConfirmToken ) Error ( ) string {
return fmt . Sprintf ( "Invalid email confirm token [Token: %s]" , err . Token )
}
// ErrCodeInvalidEmailConfirmToken holds the unique world-error code of this error
const ErrCodeInvalidEmailConfirmToken = 1010
// HTTPError holds the http error description
func ( err ErrInvalidEmailConfirmToken ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeInvalidEmailConfirmToken , Message : "Invalid email confirm token." }
}
// IsErrInvalidEmailConfirmToken checks if an error is a ErrInvalidEmailConfirmToken.
func IsErrInvalidEmailConfirmToken ( err error ) bool {
_ , ok := err . ( ErrInvalidEmailConfirmToken )
return ok
}
2018-11-01 23:47:41 +01:00
// ErrWrongUsernameOrPassword is an error where the email was not confirmed
type ErrWrongUsernameOrPassword struct {
}
func ( err ErrWrongUsernameOrPassword ) Error ( ) string {
return fmt . Sprintf ( "Wrong username or password" )
}
// ErrCodeWrongUsernameOrPassword holds the unique world-error code of this error
const ErrCodeWrongUsernameOrPassword = 1011
// HTTPError holds the http error description
func ( err ErrWrongUsernameOrPassword ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeWrongUsernameOrPassword , Message : "Wrong username or password." }
}
// IsErrWrongUsernameOrPassword checks if an error is a IsErrEmailNotConfirmed.
func IsErrWrongUsernameOrPassword ( err error ) bool {
_ , ok := err . ( ErrWrongUsernameOrPassword )
return ok
}
// ErrEmailNotConfirmed is an error where the email was not confirmed
type ErrEmailNotConfirmed struct {
UserID int64
}
func ( err ErrEmailNotConfirmed ) Error ( ) string {
return fmt . Sprintf ( "Email is not confirmed [UserID: %d]" , err . UserID )
}
// ErrCodeEmailNotConfirmed holds the unique world-error code of this error
const ErrCodeEmailNotConfirmed = 1012
// HTTPError holds the http error description
func ( err ErrEmailNotConfirmed ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusPreconditionFailed , Code : ErrCodeEmailNotConfirmed , Message : "Please confirm your email address." }
}
// IsErrEmailNotConfirmed checks if an error is a IsErrEmailNotConfirmed.
func IsErrEmailNotConfirmed ( err error ) bool {
_ , ok := err . ( ErrEmailNotConfirmed )
return ok
}
2018-06-10 11:11:41 +02:00
// ===================
// 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 {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "ID cannot be empty or 0" )
2018-06-10 14:14:10 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeIDCannotBeZero holds the unique world-error code of this error
const ErrCodeIDCannotBeZero = 2001
// HTTPError holds the http error description
func ( err ErrIDCannotBeZero ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeIDCannotBeZero , Message : "The ID cannot be empty or 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-10-06 15:04:14 +02:00
// ErrCodeListDoesNotExist holds the unique world-error code of this error
const ErrCodeListDoesNotExist = 3001
// HTTPError holds the http error description
func ( err ErrListDoesNotExist ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusNotFound , Code : ErrCodeListDoesNotExist , Message : "This list does not exist." }
}
2018-07-24 17:29:13 +02:00
// ErrNeedToHaveListReadAccess represents an error, where the user dont has read access to that List
type ErrNeedToHaveListReadAccess struct {
ListID int64
2018-07-24 17:47:08 +02:00
UserID int64
2018-07-24 17:29:13 +02:00
}
// IsErrNeedToHaveListReadAccess checks if an error is a ErrListDoesNotExist.
func IsErrNeedToHaveListReadAccess ( err error ) bool {
_ , ok := err . ( ErrNeedToHaveListReadAccess )
return ok
}
func ( err ErrNeedToHaveListReadAccess ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User needs to have read access to that list [ListID: %d, UserID: %d]" , err . ListID , err . UserID )
2018-07-24 17:29:13 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeNeedToHaveListReadAccess holds the unique world-error code of this error
const ErrCodeNeedToHaveListReadAccess = 3004
// HTTPError holds the http error description
func ( err ErrNeedToHaveListReadAccess ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusForbidden , Code : ErrCodeNeedToHaveListReadAccess , Message : "You need to have read access to this list." }
}
2018-07-26 10:29:09 +02:00
// ErrListTitleCannotBeEmpty represents a "ErrListTitleCannotBeEmpty" kind of error. Used if the list does not exist.
type ErrListTitleCannotBeEmpty struct { }
// IsErrListTitleCannotBeEmpty checks if an error is a ErrListTitleCannotBeEmpty.
func IsErrListTitleCannotBeEmpty ( err error ) bool {
_ , ok := err . ( ErrListTitleCannotBeEmpty )
return ok
}
func ( err ErrListTitleCannotBeEmpty ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "List title cannot be empty." )
2018-07-26 10:29:09 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeListTitleCannotBeEmpty holds the unique world-error code of this error
const ErrCodeListTitleCannotBeEmpty = 3005
// HTTPError holds the http error description
func ( err ErrListTitleCannotBeEmpty ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeListTitleCannotBeEmpty , Message : "You must provide at least a list title." }
}
2018-06-12 18:46:59 +02:00
// ================
2018-08-30 08:09:17 +02:00
// List task errors
2018-06-12 18:46:59 +02:00
// ================
2018-08-30 08:09:17 +02:00
// ErrListTaskCannotBeEmpty represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
type ErrListTaskCannotBeEmpty struct { }
2018-06-10 19:49:40 +02:00
2018-08-30 08:09:17 +02:00
// IsErrListTaskCannotBeEmpty checks if an error is a ErrListDoesNotExist.
func IsErrListTaskCannotBeEmpty ( err error ) bool {
_ , ok := err . ( ErrListTaskCannotBeEmpty )
2018-06-10 19:49:40 +02:00
return ok
}
2018-08-30 08:09:17 +02:00
func ( err ErrListTaskCannotBeEmpty ) Error ( ) string {
return fmt . Sprintf ( "List task text cannot be empty." )
2018-06-10 19:49:40 +02:00
}
2018-06-12 18:35:36 +02:00
2018-10-06 15:04:14 +02:00
// ErrCodeListTaskCannotBeEmpty holds the unique world-error code of this error
const ErrCodeListTaskCannotBeEmpty = 4001
// HTTPError holds the http error description
func ( err ErrListTaskCannotBeEmpty ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeListTaskCannotBeEmpty , Message : "You must provide at least a list task text." }
}
2018-08-30 08:09:17 +02:00
// ErrListTaskDoesNotExist represents a "ErrListDoesNotExist" kind of error. Used if the list does not exist.
type ErrListTaskDoesNotExist struct {
2018-06-12 18:35:36 +02:00
ID int64
}
2018-08-30 08:09:17 +02:00
// IsErrListTaskDoesNotExist checks if an error is a ErrListDoesNotExist.
func IsErrListTaskDoesNotExist ( err error ) bool {
_ , ok := err . ( ErrListTaskDoesNotExist )
2018-06-12 18:35:36 +02:00
return ok
}
2018-08-30 08:09:17 +02:00
func ( err ErrListTaskDoesNotExist ) Error ( ) string {
return fmt . Sprintf ( "List task does not exist. [ID: %d]" , err . ID )
2018-06-12 18:35:36 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeListTaskDoesNotExist holds the unique world-error code of this error
const ErrCodeListTaskDoesNotExist = 4002
// HTTPError holds the http error description
func ( err ErrListTaskDoesNotExist ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusNotFound , Code : ErrCodeListTaskDoesNotExist , Message : "This list task does not exist" }
}
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 )
}
2018-10-06 15:04:14 +02:00
// ErrCodeNamespaceDoesNotExist holds the unique world-error code of this error
const ErrCodeNamespaceDoesNotExist = 5001
// HTTPError holds the http error description
func ( err ErrNamespaceDoesNotExist ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusNotFound , Code : ErrCodeNamespaceDoesNotExist , Message : "Namespace not found." }
}
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-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User does not have access to the namespace [NamespaceID: %d, UserID: %d]" , err . NamespaceID , err . UserID )
2018-07-04 08:56:52 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeUserDoesNotHaveAccessToNamespace holds the unique world-error code of this error
const ErrCodeUserDoesNotHaveAccessToNamespace = 5003
// HTTPError holds the http error description
func ( err ErrUserDoesNotHaveAccessToNamespace ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusForbidden , Code : ErrCodeUserDoesNotHaveAccessToNamespace , Message : "This user does not have access to the namespace." }
}
2018-07-12 00:09:16 +02:00
// ErrNamespaceNameCannotBeEmpty represents an error, where a namespace name is empty.
type ErrNamespaceNameCannotBeEmpty struct {
NamespaceID int64
UserID int64
}
// IsErrNamespaceNameCannotBeEmpty checks if an error is a ErrNamespaceDoesNotExist.
func IsErrNamespaceNameCannotBeEmpty ( err error ) bool {
_ , ok := err . ( ErrNamespaceNameCannotBeEmpty )
return ok
}
func ( err ErrNamespaceNameCannotBeEmpty ) Error ( ) string {
2018-09-23 21:15:14 +02:00
return fmt . Sprintf ( "Namespace name cannot be empty [NamespaceID: %d, UserID: %d]" , err . NamespaceID , err . UserID )
2018-07-12 00:30:31 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeNamespaceNameCannotBeEmpty holds the unique world-error code of this error
const ErrCodeNamespaceNameCannotBeEmpty = 5006
// HTTPError holds the http error description
func ( err ErrNamespaceNameCannotBeEmpty ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeNamespaceNameCannotBeEmpty , Message : "The namespace name cannot be empty." }
}
2018-07-18 22:06:29 +02:00
// ErrNeedToHaveNamespaceReadAccess represents an error, where the user is not the owner of that namespace (used i.e. when deleting a namespace)
type ErrNeedToHaveNamespaceReadAccess struct {
NamespaceID int64
UserID int64
}
// IsErrNeedToHaveNamespaceReadAccess checks if an error is a ErrNamespaceDoesNotExist.
func IsErrNeedToHaveNamespaceReadAccess ( err error ) bool {
_ , ok := err . ( ErrNeedToHaveNamespaceReadAccess )
return ok
}
func ( err ErrNeedToHaveNamespaceReadAccess ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User does not have access to that namespace [NamespaceID: %d, UserID: %d]" , err . NamespaceID , err . UserID )
2018-10-06 15:04:14 +02:00
}
// ErrCodeNeedToHaveNamespaceReadAccess holds the unique world-error code of this error
const ErrCodeNeedToHaveNamespaceReadAccess = 5009
// HTTPError holds the http error description
func ( err ErrNeedToHaveNamespaceReadAccess ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusForbidden , Code : ErrCodeNeedToHaveNamespaceReadAccess , Message : "You need to have namespace read access to do this." }
2018-07-18 22:06:29 +02:00
}
2018-08-30 19:00:27 +02:00
// ErrTeamDoesNotHaveAccessToNamespace represents an error, where the Team is not the owner of that namespace (used i.e. when deleting a namespace)
type ErrTeamDoesNotHaveAccessToNamespace struct {
NamespaceID int64
TeamID int64
}
// IsErrTeamDoesNotHaveAccessToNamespace checks if an error is a ErrNamespaceDoesNotExist.
func IsErrTeamDoesNotHaveAccessToNamespace ( err error ) bool {
_ , ok := err . ( ErrTeamDoesNotHaveAccessToNamespace )
return ok
}
func ( err ErrTeamDoesNotHaveAccessToNamespace ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "Team does not have access to that namespace [NamespaceID: %d, TeamID: %d]" , err . NamespaceID , err . TeamID )
2018-08-30 19:00:27 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeTeamDoesNotHaveAccessToNamespace holds the unique world-error code of this error
const ErrCodeTeamDoesNotHaveAccessToNamespace = 5010
// HTTPError holds the http error description
func ( err ErrTeamDoesNotHaveAccessToNamespace ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusForbidden , Code : ErrCodeTeamDoesNotHaveAccessToNamespace , Message : "You need to have access to this namespace to do this." }
}
2018-09-04 20:15:24 +02:00
// ErrUserAlreadyHasNamespaceAccess represents an error where a user already has access to a namespace
type ErrUserAlreadyHasNamespaceAccess struct {
UserID int64
NamespaceID int64
}
// IsErrUserAlreadyHasNamespaceAccess checks if an error is ErrUserAlreadyHasNamespaceAccess.
func IsErrUserAlreadyHasNamespaceAccess ( err error ) bool {
_ , ok := err . ( ErrUserAlreadyHasNamespaceAccess )
return ok
}
func ( err ErrUserAlreadyHasNamespaceAccess ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User already has access to that namespace. [User ID: %d, Namespace ID: %d]" , err . UserID , err . NamespaceID )
2018-09-04 20:15:24 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeUserAlreadyHasNamespaceAccess holds the unique world-error code of this error
const ErrCodeUserAlreadyHasNamespaceAccess = 5011
// HTTPError holds the http error description
func ( err ErrUserAlreadyHasNamespaceAccess ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusConflict , Code : ErrCodeUserAlreadyHasNamespaceAccess , Message : "This user already has access to this namespace." }
}
2018-07-14 17:34:59 +02:00
// ============
// Team errors
// ============
2018-07-14 18:29:24 +02:00
// ErrTeamNameCannotBeEmpty represents an error where a team name is empty.
2018-07-14 17:34:59 +02:00
type ErrTeamNameCannotBeEmpty struct {
TeamID int64
}
// IsErrTeamNameCannotBeEmpty checks if an error is a ErrNamespaceDoesNotExist.
func IsErrTeamNameCannotBeEmpty ( err error ) bool {
_ , ok := err . ( ErrTeamNameCannotBeEmpty )
return ok
}
func ( err ErrTeamNameCannotBeEmpty ) Error ( ) string {
return fmt . Sprintf ( "Team name cannot be empty [Team ID: %d]" , err . TeamID )
}
2018-07-14 18:29:24 +02:00
2018-10-06 15:04:14 +02:00
// ErrCodeTeamNameCannotBeEmpty holds the unique world-error code of this error
const ErrCodeTeamNameCannotBeEmpty = 6001
// HTTPError holds the http error description
func ( err ErrTeamNameCannotBeEmpty ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeTeamNameCannotBeEmpty , Message : "The team name cannot be empty" }
}
2018-07-14 18:29:24 +02:00
// ErrTeamDoesNotExist represents an error where a team does not exist
type ErrTeamDoesNotExist struct {
TeamID int64
}
// IsErrTeamDoesNotExist checks if an error is ErrTeamDoesNotExist.
func IsErrTeamDoesNotExist ( err error ) bool {
_ , ok := err . ( ErrTeamDoesNotExist )
return ok
}
func ( err ErrTeamDoesNotExist ) Error ( ) string {
return fmt . Sprintf ( "Team does not exist [Team ID: %d]" , err . TeamID )
}
2018-07-17 08:44:21 +02:00
2018-10-06 15:04:14 +02:00
// ErrCodeTeamDoesNotExist holds the unique world-error code of this error
const ErrCodeTeamDoesNotExist = 6002
// HTTPError holds the http error description
func ( err ErrTeamDoesNotExist ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusNotFound , Code : ErrCodeTeamDoesNotExist , Message : "This team does not exist." }
}
2018-07-17 08:44:21 +02:00
// ErrInvalidTeamRight represents an error where a team right is invalid
type ErrInvalidTeamRight struct {
2018-07-24 17:29:13 +02:00
Right TeamRight
2018-07-17 08:44:21 +02:00
}
// IsErrInvalidTeamRight checks if an error is ErrInvalidTeamRight.
func IsErrInvalidTeamRight ( err error ) bool {
_ , ok := err . ( ErrInvalidTeamRight )
return ok
}
func ( err ErrInvalidTeamRight ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "Team right invalid [Right: %d]" , err . Right )
2018-07-17 08:44:21 +02:00
}
2018-07-24 17:46:32 +02:00
2018-10-06 15:04:14 +02:00
// ErrCodeInvalidTeamRight holds the unique world-error code of this error
const ErrCodeInvalidTeamRight = 6003
// HTTPError holds the http error description
func ( err ErrInvalidTeamRight ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeInvalidTeamRight , Message : "The team right is invalid." }
}
2018-07-24 17:46:32 +02:00
// ErrTeamAlreadyHasAccess represents an error where a team already has access to a list/namespace
type ErrTeamAlreadyHasAccess struct {
TeamID int64
2018-07-24 17:47:08 +02:00
ID int64
2018-07-24 17:46:32 +02:00
}
// IsErrTeamAlreadyHasAccess checks if an error is ErrTeamAlreadyHasAccess.
func IsErrTeamAlreadyHasAccess ( err error ) bool {
_ , ok := err . ( ErrTeamAlreadyHasAccess )
return ok
}
func ( err ErrTeamAlreadyHasAccess ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "Team already has access. [Team ID: %d, ID: %d]" , err . TeamID , err . ID )
2018-07-24 17:47:08 +02:00
}
2018-07-26 10:06:41 +02:00
2018-10-06 15:04:14 +02:00
// ErrCodeTeamAlreadyHasAccess holds the unique world-error code of this error
const ErrCodeTeamAlreadyHasAccess = 6004
// HTTPError holds the http error description
func ( err ErrTeamAlreadyHasAccess ) HTTPError ( ) HTTPError {
2018-10-06 18:32:33 +02:00
return HTTPError { HTTPCode : http . StatusConflict , Code : ErrCodeTeamAlreadyHasAccess , Message : "This team already has access." }
2018-10-06 15:04:14 +02:00
}
2018-07-26 10:06:41 +02:00
// ErrUserIsMemberOfTeam represents an error where a user is already member of a team.
type ErrUserIsMemberOfTeam struct {
TeamID int64
2018-07-26 10:08:01 +02:00
UserID int64
2018-07-26 10:06:41 +02:00
}
// IsErrUserIsMemberOfTeam checks if an error is ErrUserIsMemberOfTeam.
func IsErrUserIsMemberOfTeam ( err error ) bool {
_ , ok := err . ( ErrUserIsMemberOfTeam )
return ok
}
func ( err ErrUserIsMemberOfTeam ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User is already a member of that team. [Team ID: %d, User ID: %d]" , err . TeamID , err . UserID )
2018-07-26 10:08:01 +02:00
}
2018-07-27 19:20:49 +02:00
2018-10-06 15:04:14 +02:00
// ErrCodeUserIsMemberOfTeam holds the unique world-error code of this error
const ErrCodeUserIsMemberOfTeam = 6005
// HTTPError holds the http error description
func ( err ErrUserIsMemberOfTeam ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusConflict , Code : ErrCodeUserIsMemberOfTeam , Message : "This user is already a member of that team." }
}
2018-07-27 19:20:49 +02:00
// ErrCannotDeleteLastTeamMember represents an error where a user wants to delete the last member of a team (probably himself)
type ErrCannotDeleteLastTeamMember struct {
TeamID int64
UserID int64
}
// IsErrCannotDeleteLastTeamMember checks if an error is ErrCannotDeleteLastTeamMember.
func IsErrCannotDeleteLastTeamMember ( err error ) bool {
_ , ok := err . ( ErrCannotDeleteLastTeamMember )
return ok
}
func ( err ErrCannotDeleteLastTeamMember ) Error ( ) string {
2018-10-06 15:04:14 +02:00
return fmt . Sprintf ( "Cannot delete last team member. [Team ID: %d, User ID: %d]" , err . TeamID , err . UserID )
}
// ErrCodeCannotDeleteLastTeamMember holds the unique world-error code of this error
const ErrCodeCannotDeleteLastTeamMember = 6006
// HTTPError holds the http error description
func ( err ErrCannotDeleteLastTeamMember ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeCannotDeleteLastTeamMember , Message : "You cannot delete the last member of a team." }
2018-07-27 19:20:49 +02:00
}
2018-08-30 08:58:09 +02:00
2018-08-30 19:00:27 +02:00
// ErrTeamDoesNotHaveAccessToList represents an error, where the Team is not the owner of that List (used i.e. when deleting a List)
type ErrTeamDoesNotHaveAccessToList struct {
ListID int64
TeamID int64
}
// IsErrTeamDoesNotHaveAccessToList checks if an error is a ErrListDoesNotExist.
func IsErrTeamDoesNotHaveAccessToList ( err error ) bool {
_ , ok := err . ( ErrTeamDoesNotHaveAccessToList )
return ok
}
func ( err ErrTeamDoesNotHaveAccessToList ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "Team does not have access to the list [ListID: %d, TeamID: %d]" , err . ListID , err . TeamID )
2018-08-30 19:00:27 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeTeamDoesNotHaveAccessToList holds the unique world-error code of this error
const ErrCodeTeamDoesNotHaveAccessToList = 6007
// HTTPError holds the http error description
func ( err ErrTeamDoesNotHaveAccessToList ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusForbidden , Code : ErrCodeTeamDoesNotHaveAccessToList , Message : "This team does not have access to the list." }
}
2018-08-30 08:58:09 +02:00
// ====================
// User <-> List errors
// ====================
// ErrInvalidUserRight represents an error where a user right is invalid
type ErrInvalidUserRight struct {
Right UserRight
}
// IsErrInvalidUserRight checks if an error is ErrInvalidUserRight.
func IsErrInvalidUserRight ( err error ) bool {
_ , ok := err . ( ErrInvalidUserRight )
return ok
}
func ( err ErrInvalidUserRight ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User right is invalid [Right: %d]" , err . Right )
2018-08-30 08:58:09 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeInvalidUserRight holds the unique world-error code of this error
const ErrCodeInvalidUserRight = 7001
// HTTPError holds the http error description
func ( err ErrInvalidUserRight ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrCodeInvalidUserRight , Message : "The user right is invalid." }
}
2018-08-30 08:58:09 +02:00
// ErrUserAlreadyHasAccess represents an error where a user already has access to a list/namespace
type ErrUserAlreadyHasAccess struct {
UserID int64
ListID int64
}
// IsErrUserAlreadyHasAccess checks if an error is ErrUserAlreadyHasAccess.
func IsErrUserAlreadyHasAccess ( err error ) bool {
_ , ok := err . ( ErrUserAlreadyHasAccess )
return ok
}
func ( err ErrUserAlreadyHasAccess ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User already has access to that list. [User ID: %d, List ID: %d]" , err . UserID , err . ListID )
2018-08-30 08:58:09 +02:00
}
2018-08-30 18:52:12 +02:00
2018-10-06 15:04:14 +02:00
// ErrCodeUserAlreadyHasAccess holds the unique world-error code of this error
const ErrCodeUserAlreadyHasAccess = 7002
// HTTPError holds the http error description
func ( err ErrUserAlreadyHasAccess ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusConflict , Code : ErrCodeUserAlreadyHasAccess , Message : "This user already has access to this list." }
}
2018-08-30 18:52:12 +02:00
// ErrUserDoesNotHaveAccessToList represents an error, where the user is not the owner of that List (used i.e. when deleting a List)
type ErrUserDoesNotHaveAccessToList struct {
ListID int64
UserID int64
}
// IsErrUserDoesNotHaveAccessToList checks if an error is a ErrListDoesNotExist.
func IsErrUserDoesNotHaveAccessToList ( err error ) bool {
_ , ok := err . ( ErrUserDoesNotHaveAccessToList )
return ok
}
func ( err ErrUserDoesNotHaveAccessToList ) Error ( ) string {
2018-10-06 18:44:04 +02:00
return fmt . Sprintf ( "User does not have access to the list [ListID: %d, UserID: %d]" , err . ListID , err . UserID )
2018-08-30 18:52:12 +02:00
}
2018-10-06 15:04:14 +02:00
// ErrCodeUserDoesNotHaveAccessToList holds the unique world-error code of this error
const ErrCodeUserDoesNotHaveAccessToList = 7003
// HTTPError holds the http error description
func ( err ErrUserDoesNotHaveAccessToList ) HTTPError ( ) HTTPError {
return HTTPError { HTTPCode : http . StatusForbidden , Code : ErrCodeUserDoesNotHaveAccessToList , Message : "This user does not have access to the list." }
}