code.rs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 = "Workspace name can not be empty or whitespace")]
  15. WorkspaceNameInvalid = 100,
  16. #[display(fmt = "Workspace id can not be empty or whitespace")]
  17. WorkspaceIdInvalid = 101,
  18. #[display(fmt = "Color style of the App is invalid")]
  19. AppColorStyleInvalid = 102,
  20. #[display(fmt = "Workspace desc is invalid")]
  21. WorkspaceDescTooLong = 103,
  22. #[display(fmt = "Workspace description too long")]
  23. WorkspaceNameTooLong = 104,
  24. #[display(fmt = "App id can not be empty or whitespace")]
  25. AppIdInvalid = 110,
  26. #[display(fmt = "App name can not be empty or whitespace")]
  27. AppNameInvalid = 111,
  28. #[display(fmt = "View name can not be empty or whitespace")]
  29. ViewNameInvalid = 120,
  30. #[display(fmt = "Thumbnail of the view is invalid")]
  31. ViewThumbnailInvalid = 121,
  32. #[display(fmt = "View id can not be empty or whitespace")]
  33. ViewIdInvalid = 122,
  34. #[display(fmt = "View desc too long")]
  35. ViewDescTooLong = 123,
  36. #[display(fmt = "View data is invalid")]
  37. ViewDataInvalid = 124,
  38. #[display(fmt = "View name too long")]
  39. ViewNameTooLong = 125,
  40. #[display(fmt = "Connection error")]
  41. ConnectError = 200,
  42. #[display(fmt = "Email can not be empty or whitespace")]
  43. EmailIsEmpty = 300,
  44. #[display(fmt = "Email format is not valid")]
  45. EmailFormatInvalid = 301,
  46. #[display(fmt = "Email already exists")]
  47. EmailAlreadyExists = 302,
  48. #[display(fmt = "Password can not be empty or whitespace")]
  49. PasswordIsEmpty = 303,
  50. #[display(fmt = "Password format too long")]
  51. PasswordTooLong = 304,
  52. #[display(fmt = "Password contains forbidden characters.")]
  53. PasswordContainsForbidCharacters = 305,
  54. #[display(fmt = "Password should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric")]
  55. PasswordFormatInvalid = 306,
  56. #[display(fmt = "Password not match")]
  57. PasswordNotMatch = 307,
  58. #[display(fmt = "User name is too long")]
  59. UserNameTooLong = 308,
  60. #[display(fmt = "User name contain forbidden characters")]
  61. UserNameContainForbiddenCharacters = 309,
  62. #[display(fmt = "User name can not be empty or whitespace")]
  63. UserNameIsEmpty = 310,
  64. #[display(fmt = "user id is empty or whitespace")]
  65. UserIdInvalid = 311,
  66. #[display(fmt = "User not exist")]
  67. UserNotExist = 312,
  68. #[display(fmt = "Text is too long")]
  69. TextTooLong = 400,
  70. #[display(fmt = "Invalid data")]
  71. InvalidData = 401,
  72. }
  73. impl ErrorCode {
  74. pub fn value(&self) -> i32 {
  75. let code: ProtoBufErrorCode = self.clone().try_into().unwrap();
  76. code.value()
  77. }
  78. pub fn from_i32(value: i32) -> Self {
  79. match ProtoBufErrorCode::from_i32(value) {
  80. None => ErrorCode::Internal,
  81. Some(code) => ErrorCode::try_from(&code).unwrap(),
  82. }
  83. }
  84. }