ApiException.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package com.yihu.base.security.exception;
  2. /**
  3. * API 异常。使用错误代码初始化,并可接收用于补充错误消息的参数。
  4. * 用于描述错误代码的信息配置在各服务配置文件中,并由服务配置中心统一管理。
  5. * <p>
  6. * 错误描述结构,结构(字段errors对资源而言,REST规范错误不包含此结构):
  7. * {
  8. * "message": "Validation Failed",
  9. * "document_url": "https://ehr.yihu.com/docs/api/somewhere"
  10. * "errors": [
  11. * {
  12. * "resource": "User",
  13. * "field": "title",
  14. * "code": "missing_field"
  15. * }
  16. * ]
  17. * }
  18. *
  19. * @author Sand
  20. * @version 1.0
  21. * @created 2015.12.20 16:05
  22. */
  23. public class ApiException extends RuntimeException {
  24. private Integer errorCode = -10000;
  25. public Integer getErrorCode() {
  26. return errorCode;
  27. }
  28. public void setErrorCode(Integer errorCode) {
  29. this.errorCode = errorCode;
  30. }
  31. public ApiException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
  32. super(message, cause, enableSuppression, writableStackTrace);
  33. }
  34. public ApiException() {
  35. }
  36. public ApiException(String message) {
  37. super(message);
  38. }
  39. public ApiException(String message, Integer errorCode) {
  40. super(message);
  41. this.errorCode = errorCode;
  42. }
  43. public ApiException(String message, Throwable cause) {
  44. super(message, cause);
  45. }
  46. public ApiException(Throwable cause) {
  47. super(cause);
  48. }
  49. }