unierror.uts 894 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* 此规范为 uni 规范,可以按照自己的需要选择是否实现 */
  2. import { MyApiErrorCode, MyApiFail } from "./interface.uts"
  3. /**
  4. * 错误主题
  5. * 注意:错误主题一般为插件名称,每个组件不同,需要使用时请更改。
  6. * [可选实现]
  7. */
  8. export const UniErrorSubject = 'uts-api';
  9. /**
  10. * 错误信息
  11. * @UniError
  12. * [可选实现]
  13. */
  14. export const MyAPIErrors : Map<MyApiErrorCode, string> = new Map([
  15. /**
  16. * 错误码及对应的错误信息
  17. */
  18. [9010001, 'custom error mseeage1'],
  19. [9010002, 'custom error mseeage2'],
  20. ]);
  21. /**
  22. * 错误对象实现
  23. */
  24. export class MyApiFailImpl extends UniError implements MyApiFail {
  25. /**
  26. * 错误对象构造函数
  27. */
  28. constructor(errCode : MyApiErrorCode) {
  29. super();
  30. this.errSubject = UniErrorSubject;
  31. this.errCode = errCode;
  32. this.errMsg = MyAPIErrors.get(errCode) ?? "";
  33. }
  34. }