code.rs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. use crate::protobuf::ErrorCode as ProtoBufErrorCode;
  2. use derive_more::Display;
  3. use flowy_derive::ProtoBuf_Enum;
  4. use protobuf::ProtobufEnum;
  5. use std::convert::{TryFrom, TryInto};
  6. #[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)]
  7. pub enum ErrorCode {
  8. #[display(fmt = "Internal error")]
  9. Internal = 0,
  10. #[display(fmt = "UserUnauthorized")]
  11. UserUnauthorized = 2,
  12. #[display(fmt = "RecordNotFound")]
  13. RecordNotFound = 3,
  14. #[display(fmt = "User id is empty")]
  15. UserIdIsEmpty = 4,
  16. #[display(fmt = "Workspace name can not be empty or whitespace")]
  17. WorkspaceNameInvalid = 100,
  18. #[display(fmt = "Workspace id can not be empty or whitespace")]
  19. WorkspaceIdInvalid = 101,
  20. #[display(fmt = "Color style of the App is invalid")]
  21. AppColorStyleInvalid = 102,
  22. #[display(fmt = "Workspace desc is invalid")]
  23. WorkspaceDescTooLong = 103,
  24. #[display(fmt = "Workspace description too long")]
  25. WorkspaceNameTooLong = 104,
  26. #[display(fmt = "App id can not be empty or whitespace")]
  27. AppIdInvalid = 110,
  28. #[display(fmt = "App name can not be empty or whitespace")]
  29. AppNameInvalid = 111,
  30. #[display(fmt = "View name can not be empty or whitespace")]
  31. ViewNameInvalid = 120,
  32. #[display(fmt = "Thumbnail of the view is invalid")]
  33. ViewThumbnailInvalid = 121,
  34. #[display(fmt = "View id can not be empty or whitespace")]
  35. ViewIdInvalid = 122,
  36. #[display(fmt = "View desc too long")]
  37. ViewDescTooLong = 123,
  38. #[display(fmt = "View data is invalid")]
  39. ViewDataInvalid = 124,
  40. #[display(fmt = "View name too long")]
  41. ViewNameTooLong = 125,
  42. #[display(fmt = "Connection error")]
  43. ConnectError = 200,
  44. #[display(fmt = "Email can not be empty or whitespace")]
  45. EmailIsEmpty = 300,
  46. #[display(fmt = "Email format is not valid")]
  47. EmailFormatInvalid = 301,
  48. #[display(fmt = "Email already exists")]
  49. EmailAlreadyExists = 302,
  50. #[display(fmt = "Password can not be empty or whitespace")]
  51. PasswordIsEmpty = 303,
  52. #[display(fmt = "Password format too long")]
  53. PasswordTooLong = 304,
  54. #[display(fmt = "Password contains forbidden characters.")]
  55. PasswordContainsForbidCharacters = 305,
  56. #[display(fmt = "Password should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric")]
  57. PasswordFormatInvalid = 306,
  58. #[display(fmt = "Password not match")]
  59. PasswordNotMatch = 307,
  60. #[display(fmt = "User name is too long")]
  61. UserNameTooLong = 308,
  62. #[display(fmt = "User name contain forbidden characters")]
  63. UserNameContainForbiddenCharacters = 309,
  64. #[display(fmt = "User name can not be empty or whitespace")]
  65. UserNameIsEmpty = 310,
  66. #[display(fmt = "user id is empty or whitespace")]
  67. UserIdInvalid = 311,
  68. #[display(fmt = "User not exist")]
  69. UserNotExist = 312,
  70. #[display(fmt = "Text is too long")]
  71. TextTooLong = 400,
  72. #[display(fmt = "Grid id is empty")]
  73. GridIdIsEmpty = 410,
  74. #[display(fmt = "Grid view id is empty")]
  75. GridViewIdIsEmpty = 411,
  76. #[display(fmt = "Grid block id is empty")]
  77. BlockIdIsEmpty = 420,
  78. #[display(fmt = "Row id is empty")]
  79. RowIdIsEmpty = 430,
  80. #[display(fmt = "Select option id is empty")]
  81. OptionIdIsEmpty = 431,
  82. #[display(fmt = "Field id is empty")]
  83. FieldIdIsEmpty = 440,
  84. #[display(fmt = "Field doesn't exist")]
  85. FieldDoesNotExist = 441,
  86. #[display(fmt = "The name of the option should not be empty")]
  87. SelectOptionNameIsEmpty = 442,
  88. #[display(fmt = "Field not exists")]
  89. FieldNotExists = 443,
  90. #[display(fmt = "The operation in this field is invalid")]
  91. FieldInvalidOperation = 444,
  92. #[display(fmt = "Field's type option data should not be empty")]
  93. TypeOptionDataIsEmpty = 450,
  94. #[display(fmt = "Group id is empty")]
  95. GroupIdIsEmpty = 460,
  96. #[display(fmt = "Invalid date time format")]
  97. InvalidDateTimeFormat = 500,
  98. #[display(fmt = "The input string is empty or contains invalid characters")]
  99. UnexpectedEmptyString = 999,
  100. #[display(fmt = "Invalid data")]
  101. InvalidData = 1000,
  102. #[display(fmt = "Out of bounds")]
  103. OutOfBounds = 10001,
  104. }
  105. impl ErrorCode {
  106. pub fn value(&self) -> i32 {
  107. let code: ProtoBufErrorCode = self.clone().try_into().unwrap();
  108. code.value()
  109. }
  110. pub fn from_i32(value: i32) -> Self {
  111. match ProtoBufErrorCode::from_i32(value) {
  112. None => ErrorCode::Internal,
  113. Some(code) => ErrorCode::try_from(&code).unwrap(),
  114. }
  115. }
  116. }