ApiException.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.yihu.jw.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 ApiException() {
  26. }
  27. public ApiException(String message) {
  28. super(message);
  29. }
  30. public ApiException(String message, Integer errorCode) {
  31. super(message);
  32. this.errorCode = errorCode;
  33. }
  34. public ApiException(String message, Throwable cause) {
  35. super(message, cause);
  36. }
  37. public ApiException(Throwable cause) {
  38. super(cause);
  39. }
  40. public ApiException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
  41. super(message, cause, enableSuppression, writableStackTrace);
  42. }
  43. public Integer getErrorCode() {
  44. return errorCode;
  45. }
  46. public void setErrorCode(Integer errorCode) {
  47. this.errorCode = errorCode;
  48. }
  49. }