gcode.go 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. // Package gcode provides universal error code definition and common error codes implements.
  7. package gcode
  8. // Code is universal error code interface definition.
  9. type Code interface {
  10. // Code returns the integer number of current error code.
  11. Code() int
  12. // Message returns the brief message for current error code.
  13. Message() string
  14. // Detail returns the detailed information of current error code,
  15. // which is mainly designed as an extension field for error code.
  16. Detail() interface{}
  17. }
  18. // ================================================================================================================
  19. // Common error code definition.
  20. // There are reserved internal error code by framework: code < 1000.
  21. // ================================================================================================================
  22. var (
  23. CodeNil = localCode{-1, "", nil} // No error code specified.
  24. CodeOK = localCode{0, "OK", nil} // It is OK.
  25. CodeInternalError = localCode{50, "Internal Error", nil} // An error occurred internally.
  26. CodeValidationFailed = localCode{51, "Validation Failed", nil} // Data validation failed.
  27. CodeDbOperationError = localCode{52, "Database Operation Error", nil} // Database operation error.
  28. CodeInvalidParameter = localCode{53, "Invalid Parameter", nil} // The given parameter for current operation is invalid.
  29. CodeMissingParameter = localCode{54, "Missing Parameter", nil} // Parameter for current operation is missing.
  30. CodeInvalidOperation = localCode{55, "Invalid Operation", nil} // The function cannot be used like this.
  31. CodeInvalidConfiguration = localCode{56, "Invalid Configuration", nil} // The configuration is invalid for current operation.
  32. CodeMissingConfiguration = localCode{57, "Missing Configuration", nil} // The configuration is missing for current operation.
  33. CodeNotImplemented = localCode{58, "Not Implemented", nil} // The operation is not implemented yet.
  34. CodeNotSupported = localCode{59, "Not Supported", nil} // The operation is not supported yet.
  35. CodeOperationFailed = localCode{60, "Operation Failed", nil} // I tried, but I cannot give you what you want.
  36. CodeNotAuthorized = localCode{61, "Not Authorized", nil} // Not Authorized.
  37. CodeSecurityReason = localCode{62, "Security Reason", nil} // Security Reason.
  38. CodeServerBusy = localCode{63, "Server Is Busy", nil} // Server is busy, please try again later.
  39. CodeUnknown = localCode{64, "Unknown Error", nil} // Unknown error.
  40. CodeNotFound = localCode{65, "Not Found", nil} // Resource does not exist.
  41. CodeInvalidRequest = localCode{66, "Invalid Request", nil} // Invalid request.
  42. CodeBusinessValidationFailed = localCode{300, "Business Validation Failed", nil} // Business validation failed.
  43. )
  44. // New creates and returns an error code.
  45. // Note that it returns an interface object of Code.
  46. func New(code int, message string, detail interface{}) Code {
  47. return localCode{
  48. code: code,
  49. message: message,
  50. detail: detail,
  51. }
  52. }