unierror.uts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { WifiErrorCode, WifiFail} from "./interface.uts"
  2. /**
  3. * 错误主题
  4. */
  5. export const UniErrorSubject = 'uni-wifi';
  6. /**
  7. * 错误码
  8. * @UniError
  9. */
  10. export const WifiUniErrors : Map<WifiErrorCode, string> = new Map([
  11. /**
  12. * 未先调用 startWifi 接口
  13. */
  14. [12000, 'not init.'],
  15. /**
  16. * 当前系统不支持相关能力
  17. */
  18. [12001, 'system not support'],
  19. /**
  20. * 密码错误
  21. */
  22. [12002, 'password error Wi-Fi'],
  23. /**
  24. * Android 特有,未打开 Wi-Fi 开关
  25. */
  26. [12005, 'wifi not turned on'],
  27. /**
  28. * 用户拒绝授权链接 Wi-Fi
  29. */
  30. [12007, 'user denied'],
  31. /**
  32. * 系统其他错误,需要在 errmsg 打印具体的错误原因
  33. */
  34. [12010, 'unknown error'],
  35. /**
  36. * 系统保存的 Wi-Fi 配置过期,建议忘记 Wi-Fi 后重试,仅 Android 支持
  37. */
  38. [12013, 'wifi config may be expired'],
  39. ]);
  40. export function getErrcode(errCode : number) : WifiErrorCode {
  41. const res = WifiUniErrors[errCode];
  42. return res == null ? 12000 : errCode;
  43. }
  44. export class WifiFailImpl extends UniError implements WifiFail {
  45. constructor(errCode : WifiErrorCode) {
  46. super();
  47. this.errSubject = UniErrorSubject;
  48. this.errCode = errCode;
  49. this.errMsg = WifiUniErrors[errCode] ?? "";
  50. }
  51. }