ErrorEnum.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.ym.common;
  2. import lombok.Getter;
  3. /**
  4. * Created by weiqinxiao on 2019/2/25.
  5. */
  6. public enum ErrorEnum {
  7. ERR_SUCCESS(0x0000, "OK"),
  8. ERR_OTHER(0x00FF, "Error"),
  9. ERR_REQUEST_PARA_ERR(1, "Missing or invalid parameter"),
  10. ERR_INVALID_AUTH(2, "Invalid or expired authorization"),
  11. ERR_ACCESS_DENIED(3, "Access denied"),
  12. ERR_BAD_REQUEST(4, "Bad request"),
  13. //IM error
  14. ERR_IM_TOKEN_ERROR(10, "IM token error"),
  15. ERR_CREATE_ROOM_ERROR(11, "Create room error"),
  16. ERR_JOIN_ROOM_ERROR(12, "Join room error"),
  17. JOIN_ROOM_ERROR(35, "加入房间失败,请前往线下教室"),
  18. ERR_MESSAGE_ERROR(13, "IM Message send error"),
  19. //room error
  20. ERR_ROOM_NOT_EXIST(20, "Room not exist"),
  21. ERR_USER_NOT_EXIST_IN_ROOM(21, "User not exist in room"),
  22. ERR_EXIT_ROOM_ERROR(22, "Exit room error"),
  23. ERR_TEACHER_NOT_EXIST_IN_ROOM(23, "Teacher not exist in room"),
  24. ERR_ASSISTANT_NOT_EXIST_IN_ROOM(24, "Assistant not exist in room"),
  25. ERR_CREATE_WHITE_BOARD(25, "Create whiteboard error"),
  26. ERR_WHITE_BOARD_NOT_EXIST(26, "Whiteboard not exist"),
  27. ERR_DELETE_WHITE_BOARD(27, "Delete whiteboard error"),
  28. ERR_USER_EXIST_IN_ROOM(28, "User exist in room"),
  29. ERR_CHANGE_SELF_ROLE(29, "Can not change self role"),
  30. ERR_APPLY_TICKET_INVALID(30, "Apply ticket invalid"),
  31. ERR_OVER_MAX_COUNT(31, "Over max count"),
  32. ERR_TEACHER_EXIST_IN_ROOM(32, "Teacher exist in room"),
  33. ERR_DOWNGRADE_ROLE(33, "Can't downgrade role"),
  34. ERR_CHANGE_ROLE(34, "Only change student to teacher");
  35. private @Getter int errCode;
  36. private @Getter String errMsg;
  37. private ErrorEnum(int errCode, String errMsg) {
  38. this.errCode = errCode;
  39. this.errMsg = errMsg;
  40. }
  41. public static ErrorEnum getEnumByValue(long errCode) {
  42. for(ErrorEnum item : ErrorEnum.values()) {
  43. if(item.getErrCode() == errCode) {
  44. return item;
  45. }
  46. }
  47. throw new IllegalArgumentException();
  48. }
  49. }