errors.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (C) 2019-2022 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. package util
  15. import (
  16. "fmt"
  17. )
  18. const (
  19. templateLoadErrorHints = "Try setting the absolute templates path in your configuration file " +
  20. "or specifying the config directory adding the `-c` flag to the serve options. For example: " +
  21. "sftpgo serve -c \"<path to dir containing the default config file and templates directory>\""
  22. )
  23. // ValidationError raised if input data is not valid
  24. type ValidationError struct {
  25. err string
  26. }
  27. // Validation error details
  28. func (e *ValidationError) Error() string {
  29. return fmt.Sprintf("Validation error: %s", e.err)
  30. }
  31. // GetErrorString returns the unmodified error string
  32. func (e *ValidationError) GetErrorString() string {
  33. return e.err
  34. }
  35. // NewValidationError returns a validation errors
  36. func NewValidationError(error string) *ValidationError {
  37. return &ValidationError{
  38. err: error,
  39. }
  40. }
  41. // RecordNotFoundError raised if a requested object is not found
  42. type RecordNotFoundError struct {
  43. err string
  44. }
  45. func (e *RecordNotFoundError) Error() string {
  46. return fmt.Sprintf("not found: %s", e.err)
  47. }
  48. // NewRecordNotFoundError returns a not found error
  49. func NewRecordNotFoundError(error string) *RecordNotFoundError {
  50. return &RecordNotFoundError{
  51. err: error,
  52. }
  53. }
  54. // MethodDisabledError raised if a method is disabled in config file.
  55. // For example, if user management is disabled, this error is raised
  56. // every time a user operation is done using the REST API
  57. type MethodDisabledError struct {
  58. err string
  59. }
  60. // Method disabled error details
  61. func (e *MethodDisabledError) Error() string {
  62. return fmt.Sprintf("Method disabled error: %s", e.err)
  63. }
  64. // NewMethodDisabledError returns a method disabled error
  65. func NewMethodDisabledError(error string) *MethodDisabledError {
  66. return &MethodDisabledError{
  67. err: error,
  68. }
  69. }
  70. // GenericError raised for not well categorized error
  71. type GenericError struct {
  72. err string
  73. }
  74. func (e *GenericError) Error() string {
  75. return e.err
  76. }
  77. // NewGenericError returns a generic error
  78. func NewGenericError(error string) *GenericError {
  79. return &GenericError{
  80. err: error,
  81. }
  82. }