gitea源码

error.go 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package user
  4. import (
  5. "fmt"
  6. "code.gitea.io/gitea/modules/util"
  7. )
  8. // ErrUserAlreadyExist represents a "user already exists" error.
  9. type ErrUserAlreadyExist struct {
  10. Name string
  11. }
  12. // IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists.
  13. func IsErrUserAlreadyExist(err error) bool {
  14. _, ok := err.(ErrUserAlreadyExist)
  15. return ok
  16. }
  17. func (err ErrUserAlreadyExist) Error() string {
  18. return fmt.Sprintf("user already exists [name: %s]", err.Name)
  19. }
  20. // Unwrap unwraps this error as a ErrExist error
  21. func (err ErrUserAlreadyExist) Unwrap() error {
  22. return util.ErrAlreadyExist
  23. }
  24. // ErrUserNotExist represents a "UserNotExist" kind of error.
  25. type ErrUserNotExist struct {
  26. UID int64
  27. Name string
  28. }
  29. // IsErrUserNotExist checks if an error is a ErrUserNotExist.
  30. func IsErrUserNotExist(err error) bool {
  31. _, ok := err.(ErrUserNotExist)
  32. return ok
  33. }
  34. func (err ErrUserNotExist) Error() string {
  35. return fmt.Sprintf("user does not exist [uid: %d, name: %s]", err.UID, err.Name)
  36. }
  37. // Unwrap unwraps this error as a ErrNotExist error
  38. func (err ErrUserNotExist) Unwrap() error {
  39. return util.ErrNotExist
  40. }
  41. // ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error.
  42. type ErrUserProhibitLogin struct {
  43. UID int64
  44. Name string
  45. }
  46. // IsErrUserProhibitLogin checks if an error is a ErrUserProhibitLogin
  47. func IsErrUserProhibitLogin(err error) bool {
  48. _, ok := err.(ErrUserProhibitLogin)
  49. return ok
  50. }
  51. func (err ErrUserProhibitLogin) Error() string {
  52. return fmt.Sprintf("user is not allowed login [uid: %d, name: %s]", err.UID, err.Name)
  53. }
  54. // Unwrap unwraps this error as a ErrPermission error
  55. func (err ErrUserProhibitLogin) Unwrap() error {
  56. return util.ErrPermissionDenied
  57. }
  58. // ErrUserInactive represents a "ErrUserInactive" kind of error.
  59. type ErrUserInactive struct {
  60. UID int64
  61. Name string
  62. }
  63. // IsErrUserInactive checks if an error is a ErrUserInactive
  64. func IsErrUserInactive(err error) bool {
  65. _, ok := err.(ErrUserInactive)
  66. return ok
  67. }
  68. func (err ErrUserInactive) Error() string {
  69. return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
  70. }
  71. // Unwrap unwraps this error as a ErrPermission error
  72. func (err ErrUserInactive) Unwrap() error {
  73. return util.ErrPermissionDenied
  74. }
  75. // ErrUserIsNotLocal represents a "ErrUserIsNotLocal" kind of error.
  76. type ErrUserIsNotLocal struct {
  77. UID int64
  78. Name string
  79. }
  80. func (err ErrUserIsNotLocal) Error() string {
  81. return fmt.Sprintf("user is not local type [uid: %d, name: %s]", err.UID, err.Name)
  82. }
  83. // IsErrUserIsNotLocal
  84. func IsErrUserIsNotLocal(err error) bool {
  85. _, ok := err.(ErrUserIsNotLocal)
  86. return ok
  87. }