login_source.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package errors
  7. import "fmt"
  8. // LoginSourceNotExist represents a "LoginSourceNotExist" kind of error
  9. type LoginSourceNotExist struct {
  10. ID int64
  11. }
  12. // IsLoginSourceNotExist checks if an error is a LoginSourceNotExist
  13. func IsLoginSourceNotExist(err error) bool {
  14. _, ok := err.(LoginSourceNotExist)
  15. return ok
  16. }
  17. func (err LoginSourceNotExist) Error() string {
  18. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  19. }
  20. // LoginSourceNotActivated represents a "LoginSourceNotActivated" kind of error
  21. type LoginSourceNotActivated struct {
  22. SourceID int64
  23. }
  24. // IsLoginSourceNotActivated checks if an error is a LoginSourceNotActivated
  25. func IsLoginSourceNotActivated(err error) bool {
  26. _, ok := err.(LoginSourceNotActivated)
  27. return ok
  28. }
  29. func (err LoginSourceNotActivated) Error() string {
  30. return fmt.Sprintf("login source is not activated [source_id: %d]", err.SourceID)
  31. }
  32. // InvalidLoginSourceType represents a "InvalidLoginSourceType" kind of error
  33. type InvalidLoginSourceType struct {
  34. Type interface{}
  35. }
  36. // IsInvalidLoginSourceType checks if an error is a InvalidLoginSourceType
  37. func IsInvalidLoginSourceType(err error) bool {
  38. _, ok := err.(InvalidLoginSourceType)
  39. return ok
  40. }
  41. func (err InvalidLoginSourceType) Error() string {
  42. return fmt.Sprintf("invalid login source type [type: %v]", err.Type)
  43. }
  44. // LoginSourceMismatch represents a "LoginSourceMismatch" kind of error
  45. type LoginSourceMismatch struct {
  46. Expect int64
  47. Actual int64
  48. }
  49. // IsLoginSourceMismatch checks if an error is a LoginSourceMismatch
  50. func IsLoginSourceMismatch(err error) bool {
  51. _, ok := err.(LoginSourceMismatch)
  52. return ok
  53. }
  54. func (err LoginSourceMismatch) Error() string {
  55. return fmt.Sprintf("login source mismatch [expect: %d, actual: %d]", err.Expect, err.Actual)
  56. }