diff options
Diffstat (limited to 'models/errors')
-rw-r--r-- | models/errors/errors.go | 12 | ||||
-rw-r--r-- | models/errors/issue.go | 20 | ||||
-rw-r--r-- | models/errors/login_source.go | 33 | ||||
-rw-r--r-- | models/errors/repo.go | 33 | ||||
-rw-r--r-- | models/errors/user.go | 31 | ||||
-rw-r--r-- | models/errors/user_mail.go | 33 |
6 files changed, 162 insertions, 0 deletions
diff --git a/models/errors/errors.go b/models/errors/errors.go new file mode 100644 index 00000000..43ed6335 --- /dev/null +++ b/models/errors/errors.go @@ -0,0 +1,12 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "errors" + +// New is a wrapper of real errors.New function. +func New(text string) error { + return errors.New(text) +} diff --git a/models/errors/issue.go b/models/errors/issue.go new file mode 100644 index 00000000..4ea898fb --- /dev/null +++ b/models/errors/issue.go @@ -0,0 +1,20 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type InvalidIssueReference struct { + Ref string +} + +func IsInvalidIssueReference(err error) bool { + _, ok := err.(InvalidIssueReference) + return ok +} + +func (err InvalidIssueReference) Error() string { + return fmt.Sprintf("invalid issue reference [ref: %s]", err.Ref) +} diff --git a/models/errors/login_source.go b/models/errors/login_source.go new file mode 100644 index 00000000..db0cd1f9 --- /dev/null +++ b/models/errors/login_source.go @@ -0,0 +1,33 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type LoginSourceNotActivated struct { + SourceID int64 +} + +func IsLoginSourceNotActivated(err error) bool { + _, ok := err.(LoginSourceNotActivated) + return ok +} + +func (err LoginSourceNotActivated) Error() string { + return fmt.Sprintf("login source is not activated [source_id: %d]", err.SourceID) +} + +type InvalidLoginSourceType struct { + Type interface{} +} + +func IsInvalidLoginSourceType(err error) bool { + _, ok := err.(InvalidLoginSourceType) + return ok +} + +func (err InvalidLoginSourceType) Error() string { + return fmt.Sprintf("invalid login source type [type: %v]", err.Type) +} diff --git a/models/errors/repo.go b/models/errors/repo.go new file mode 100644 index 00000000..9abcaaa9 --- /dev/null +++ b/models/errors/repo.go @@ -0,0 +1,33 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type InvalidRepoReference struct { + Ref string +} + +func IsInvalidRepoReference(err error) bool { + _, ok := err.(InvalidRepoReference) + return ok +} + +func (err InvalidRepoReference) Error() string { + return fmt.Sprintf("invalid repository reference [ref: %s]", err.Ref) +} + +type MirrorNotExist struct { + RepoID int64 +} + +func IsMirrorNotExist(err error) bool { + _, ok := err.(MirrorNotExist) + return ok +} + +func (err MirrorNotExist) Error() string { + return fmt.Sprintf("mirror does not exist [repo_id: %d]", err.RepoID) +} diff --git a/models/errors/user.go b/models/errors/user.go new file mode 100644 index 00000000..cda49e0e --- /dev/null +++ b/models/errors/user.go @@ -0,0 +1,31 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type EmptyName struct{} + +func IsEmptyName(err error) bool { + _, ok := err.(EmptyName) + return ok +} + +func (err EmptyName) Error() string { + return "empty name" +} + +type UserNotKeyOwner struct { + KeyID int64 +} + +func IsUserNotKeyOwner(err error) bool { + _, ok := err.(UserNotKeyOwner) + return ok +} + +func (err UserNotKeyOwner) Error() string { + return fmt.Sprintf("user is not the owner of public key [key_id: %d]", err.KeyID) +} diff --git a/models/errors/user_mail.go b/models/errors/user_mail.go new file mode 100644 index 00000000..fcdeb78c --- /dev/null +++ b/models/errors/user_mail.go @@ -0,0 +1,33 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errors + +import "fmt" + +type EmailNotFound struct { + Email string +} + +func IsEmailNotFound(err error) bool { + _, ok := err.(EmailNotFound) + return ok +} + +func (err EmailNotFound) Error() string { + return fmt.Sprintf("email is not found [email: %s]", err.Email) +} + +type EmailNotVerified struct { + Email string +} + +func IsEmailNotVerified(err error) bool { + _, ok := err.(EmailNotVerified) + return ok +} + +func (err EmailNotVerified) Error() string { + return fmt.Sprintf("email has not been verified [email: %s]", err.Email) +} |