跳转到主要内容
版本:0.2.0-beta.1

类:MCPAuthTokenVerificationError

在验证令牌时出现问题时抛出的错误。

继承自

构造函数

构造函数

new MCPAuthTokenVerificationError(code: MCPAuthTokenVerificationErrorCode, cause?: unknown): MCPAuthTokenVerificationError;

参数

code

MCPAuthTokenVerificationErrorCode

cause?

unknown

返回

MCPAuthTokenVerificationError

重写自

MCPAuthError.constructor

属性

cause?

readonly optional cause: unknown;

继承自

MCPAuthError.cause


code

readonly code: MCPAuthTokenVerificationErrorCode;

错误代码,采用 snake_case 格式。

继承自

MCPAuthError.code


message

message: string;

继承自

MCPAuthError.message


name

name: string = 'MCPAuthTokenVerificationError';

重写自

MCPAuthError.name


stack?

optional stack: string;

继承自

MCPAuthError.stack


stackTraceLimit

static stackTraceLimit: number;

Error.stackTraceLimit 属性指定堆栈跟踪收集的堆栈帧数量(无论是由 new Error().stack 还是 Error.captureStackTrace(obj) 生成)。

默认值为 10,但可以设置为任何有效的 JavaScript 数字。更改后将影响之后捕获的所有堆栈跟踪。

如果设置为非数字值,或设置为负数,则堆栈跟踪不会捕获任何帧。

继承自

MCPAuthError.stackTraceLimit

方法

toJson()

toJson(showCause: boolean): Record<string, unknown>;

将错误转换为适合 HTTP 响应的 JSON 格式。

参数

showCause

boolean = false

是否在 JSON 响应中包含错误原因。 默认为 false

返回

Record<string, unknown>

继承自

MCPAuthError.toJson


captureStackTrace()

static captureStackTrace(targetObject: object, constructorOpt?: Function): void;

targetObject 上创建一个 .stack 属性,当访问时返回一个字符串,表示调用 Error.captureStackTrace() 时在代码中的位置。

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // 类似于 `new Error().stack`

跟踪的第一行将以 ${myObject.name}: ${myObject.message} 为前缀。

可选的 constructorOpt 参数接受一个函数。如果提供,则在生成的堆栈跟踪中,constructorOpt 及其以上的所有帧都将被省略。

constructorOpt 参数对于隐藏错误生成的实现细节很有用。例如:

function a() {
  b();
}

function b() {
  c();
}

function c() {
  // 创建一个没有堆栈跟踪的错误,以避免重复计算堆栈跟踪。
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // 捕获 b 函数以上的堆栈跟踪
  Error.captureStackTrace(error, b); // 堆栈跟踪中不包含 c 和 b 函数
  throw error;
}

a();

参数

targetObject

object

constructorOpt?

Function

返回

void

继承自

MCPAuthError.captureStackTrace


prepareStackTrace()

static prepareStackTrace(err: Error, stackTraces: CallSite[]): any;

参数

err

Error

stackTraces

CallSite[]

返回

any

参见

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

继承自

MCPAuthError.prepareStackTrace