@heybox/hb-sdk API Reference - v0.9.5
    正在准备搜索索引...

    类 HbMiniProgramSDKError

    SDK 对外抛出的标准 bridge / runtime 错误类型。

    该错误用于表示握手失败、bridge 调用失败、父容器运行时错误等 非 HTTP 结果错误。其 code 字段可用于业务分支处理, data 仅作为可选调试信息,不保证结构稳定。错误码是跨 Host 的分支契约; message 只用于日志和开发者提示,不应作为机器判断条件。

    常见处理类别包括:INVALID_PARAMS(修正调用参数)、PERMISSION_NOT_IN_SNAPSHOT (当前运行快照缺少权限,需发布含声明的新版本或重新打开调试)、 PERMISSION_DENIED(检查权限启用状态与平台批准)、USER_GESTURE_REQUIRED (改为用户点击后重试)、AUTHORIZATION_CANCELLED(结束当前流程),以及 METHOD_FORBIDDEN(当前 Host 不支持该能力)。具体能力还可能返回模块专属错误码。 旧 Runtime 仍可能返回 PERMISSION_NOT_DECLARED;SDK 会保留 Host 返回的错误码。 不要把所有错误都当作可重试错误,也不要把 data 当成稳定的序列化协议。

    • * import hbSDK, { HbMiniProgramSDKError } from '@heybox/hb-sdk'
      *
      * try {
      * await hbSDK.auth.login({ scopes: ['profile'] })

    } catch (error) { if (error instanceof HbMiniProgramSDKError && error.code === 'USER_GESTURE_REQUIRED') { showRetryButton() return } throw error }

    
    

    层级

    • Error
      • HbMiniProgramSDKError
    索引

    构造函数

    属性

    cause?: unknown
    code: string

    稳定错误码;业务分支应比较该字段,不要比较 message。

    data?: unknown

    可选调试数据;结构由具体错误码决定,可能随 Host 版本变化。

    message: string
    name: string
    stack?: string
    stackTraceLimit: number

    The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

    The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

    If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

    方法

    • Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

      const myObject = {};
      Error.captureStackTrace(myObject);
      myObject.stack; // Similar to `new Error().stack`

      The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

      The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

      The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

      function a() {
      b();
      }

      function b() {
      c();
      }

      function c() {
      // Create an error without stack trace to avoid calculating the stack trace twice.
      const { stackTraceLimit } = Error;
      Error.stackTraceLimit = 0;
      const error = new Error();
      Error.stackTraceLimit = stackTraceLimit;

      // Capture the stack trace above function b
      Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
      throw error;
      }

      a();

      参数

      • targetObject: object
      • 可选constructorOpt: Function

      返回 void

    • Indicates whether the argument provided is a built-in Error instance or not.

      参数

      • error: unknown

      返回 error is Error