error.js 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
const ERROR = {
  ACCOUNT_EXISTS: 'uni-id-account-exists',
  ACCOUNT_NOT_EXISTS: 'uni-id-account-not-exists',
  ACCOUNT_CONFLICT: 'uni-id-account-conflict',
  ACCOUNT_BANNED: 'uni-id-account-banned',
  ACCOUNT_AUDITING: 'uni-id-account-auditing',
  ACCOUNT_AUDIT_FAILED: 'uni-id-account-audit-failed',
  ACCOUNT_CLOSED: 'uni-id-account-closed',
  CAPTCHA_REQUIRED: 'uni-id-captcha-required',
  PASSWORD_ERROR: 'uni-id-password-error',
  PASSWORD_ERROR_EXCEED_LIMIT: 'uni-id-password-error-exceed-limit',
  INVALID_USERNAME: 'uni-id-invalid-username',
  INVALID_PASSWORD: 'uni-id-invalid-password',
  INVALID_PASSWORD_SUPER: 'uni-id-invalid-password-super',
  INVALID_PASSWORD_STRONG: 'uni-id-invalid-password-strong',
  INVALID_PASSWORD_MEDIUM: 'uni-id-invalid-password-medium',
  INVALID_PASSWORD_WEAK: 'uni-id-invalid-password-weak',
  INVALID_MOBILE: 'uni-id-invalid-mobile',
  INVALID_EMAIL: 'uni-id-invalid-email',
  INVALID_NICKNAME: 'uni-id-invalid-nickname',
  INVALID_PARAM: 'uni-id-invalid-param',
  PARAM_REQUIRED: 'uni-id-param-required',
  GET_THIRD_PARTY_ACCOUNT_FAILED: 'uni-id-get-third-party-account-failed',
  GET_THIRD_PARTY_USER_INFO_FAILED: 'uni-id-get-third-party-user-info-failed',
  MOBILE_VERIFY_CODE_ERROR: 'uni-id-mobile-verify-code-error',
  EMAIL_VERIFY_CODE_ERROR: 'uni-id-email-verify-code-error',
  ADMIN_EXISTS: 'uni-id-admin-exists',
  PERMISSION_ERROR: 'uni-id-permission-error',
  SYSTEM_ERROR: 'uni-id-system-error',
  SET_INVITE_CODE_FAILED: 'uni-id-set-invite-code-failed',
  INVALID_INVITE_CODE: 'uni-id-invalid-invite-code',
  CHANGE_INVITER_FORBIDDEN: 'uni-id-change-inviter-forbidden',
  BIND_CONFLICT: 'uni-id-bind-conflict'
}

function isUniIdError (errCode) {
  return Object.values(ERROR).includes(errCode)
}

class UniCloudError extends Error {
  constructor (options) {
    super(options.message)
    this.errMsg = options.message || ''
    this.errCode = options.code
  }
}

module.exports = {
  ERROR,
  isUniIdError,
  UniCloudError
}