errors.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // GetErrorString returns the unmodified error string
  12. func (e *ValidationError) GetErrorString() string {
  13. return e.err
  14. }
  15. // NewValidationError returns a validation errors
  16. func NewValidationError(error string) *ValidationError {
  17. return &ValidationError{
  18. err: error,
  19. }
  20. }
  21. // RecordNotFoundError raised if a requested object is not found
  22. type RecordNotFoundError struct {
  23. err string
  24. }
  25. func (e *RecordNotFoundError) Error() string {
  26. return fmt.Sprintf("not found: %s", e.err)
  27. }
  28. // NewRecordNotFoundError returns a not found error
  29. func NewRecordNotFoundError(error string) *RecordNotFoundError {
  30. return &RecordNotFoundError{
  31. err: error,
  32. }
  33. }
  34. // MethodDisabledError raised if a method is disabled in config file.
  35. // For example, if user management is disabled, this error is raised
  36. // every time a user operation is done using the REST API
  37. type MethodDisabledError struct {
  38. err string
  39. }
  40. // Method disabled error details
  41. func (e *MethodDisabledError) Error() string {
  42. return fmt.Sprintf("Method disabled error: %s", e.err)
  43. }
  44. // NewMethodDisabledError returns a method disabled error
  45. func NewMethodDisabledError(error string) *MethodDisabledError {
  46. return &MethodDisabledError{
  47. err: error,
  48. }
  49. }
  50. // GenericError raised for not well categorized error
  51. type GenericError struct {
  52. err string
  53. }
  54. func (e *GenericError) Error() string {
  55. return e.err
  56. }
  57. // NewGenericError returns a generic error
  58. func NewGenericError(error string) *GenericError {
  59. return &GenericError{
  60. err: error,
  61. }
  62. }