errors.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package util
  2. import "fmt"
  3. // ValidationError raised if input data is not valid
  4. type ValidationError struct {
  5. err string
  6. }
  7. // Validation error details
  8. func (e *ValidationError) Error() string {
  9. return fmt.Sprintf("Validation error: %s", e.err)
  10. }
  11. // NewValidationError returns a validation errors
  12. func NewValidationError(error string) *ValidationError {
  13. return &ValidationError{
  14. err: error,
  15. }
  16. }
  17. // RecordNotFoundError raised if a requested user is not found
  18. type RecordNotFoundError struct {
  19. err string
  20. }
  21. func (e *RecordNotFoundError) Error() string {
  22. return fmt.Sprintf("not found: %s", e.err)
  23. }
  24. // NewRecordNotFoundError returns a not found error
  25. func NewRecordNotFoundError(error string) *RecordNotFoundError {
  26. return &RecordNotFoundError{
  27. err: error,
  28. }
  29. }
  30. // MethodDisabledError raised if a method is disabled in config file.
  31. // For example, if user management is disabled, this error is raised
  32. // every time a user operation is done using the REST API
  33. type MethodDisabledError struct {
  34. err string
  35. }
  36. // Method disabled error details
  37. func (e *MethodDisabledError) Error() string {
  38. return fmt.Sprintf("Method disabled error: %s", e.err)
  39. }
  40. // NewMethodDisabledError returns a method disabled error
  41. func NewMethodDisabledError(error string) *MethodDisabledError {
  42. return &MethodDisabledError{
  43. err: error,
  44. }
  45. }