You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error.go 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. KeyID int64
  29. }
  30. // IsErrUserNotExist checks if an error is a ErrUserNotExist.
  31. func IsErrUserNotExist(err error) bool {
  32. _, ok := err.(ErrUserNotExist)
  33. return ok
  34. }
  35. func (err ErrUserNotExist) Error() string {
  36. return fmt.Sprintf("user does not exist [uid: %d, name: %s, keyid: %d]", err.UID, err.Name, err.KeyID)
  37. }
  38. // Unwrap unwraps this error as a ErrNotExist error
  39. func (err ErrUserNotExist) Unwrap() error {
  40. return util.ErrNotExist
  41. }
  42. // ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error.
  43. type ErrUserProhibitLogin struct {
  44. UID int64
  45. Name string
  46. }
  47. // IsErrUserProhibitLogin checks if an error is a ErrUserProhibitLogin
  48. func IsErrUserProhibitLogin(err error) bool {
  49. _, ok := err.(ErrUserProhibitLogin)
  50. return ok
  51. }
  52. func (err ErrUserProhibitLogin) Error() string {
  53. return fmt.Sprintf("user is not allowed login [uid: %d, name: %s]", err.UID, err.Name)
  54. }
  55. // Unwrap unwraps this error as a ErrPermission error
  56. func (err ErrUserProhibitLogin) Unwrap() error {
  57. return util.ErrPermissionDenied
  58. }
  59. // ErrUserInactive represents a "ErrUserInactive" kind of error.
  60. type ErrUserInactive struct {
  61. UID int64
  62. Name string
  63. }
  64. // IsErrUserInactive checks if an error is a ErrUserInactive
  65. func IsErrUserInactive(err error) bool {
  66. _, ok := err.(ErrUserInactive)
  67. return ok
  68. }
  69. func (err ErrUserInactive) Error() string {
  70. return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
  71. }
  72. // Unwrap unwraps this error as a ErrPermission error
  73. func (err ErrUserInactive) Unwrap() error {
  74. return util.ErrPermissionDenied
  75. }
  76. // ErrUserIsNotLocal represents a "ErrUserIsNotLocal" kind of error.
  77. type ErrUserIsNotLocal struct {
  78. UID int64
  79. Name string
  80. }
  81. func (err ErrUserIsNotLocal) Error() string {
  82. return fmt.Sprintf("user is not local type [uid: %d, name: %s]", err.UID, err.Name)
  83. }
  84. // IsErrUserIsNotLocal
  85. func IsErrUserIsNotLocal(err error) bool {
  86. _, ok := err.(ErrUserIsNotLocal)
  87. return ok
  88. }
  89. type ErrUsernameNotChanged struct {
  90. UID int64
  91. Name string
  92. }
  93. func (err ErrUsernameNotChanged) Error() string {
  94. return fmt.Sprintf("username hasn't been changed[uid: %d, name: %s]", err.UID, err.Name)
  95. }
  96. // IsErrUsernameNotChanged
  97. func IsErrUsernameNotChanged(err error) bool {
  98. _, ok := err.(ErrUsernameNotChanged)
  99. return ok
  100. }