跳转到主要内容

类:MCPAuthBearerAuthError

当使用 Bearer 令牌进行认证 (Authentication) 时出现问题时抛出的错误。

继承自​

构造函数​

构造函数​

new MCPAuthBearerAuthError(code: BearerAuthErrorCode, cause?: MCPAuthBearerAuthErrorDetails): MCPAuthBearerAuthError;

参数​

code​

BearerAuthErrorCode

cause?​

MCPAuthBearerAuthErrorDetails

返回​

MCPAuthBearerAuthError

重写自​

MCPAuthError.constructor

属性​

cause?​

readonly optional cause: MCPAuthBearerAuthErrorDetails;

继承自​

MCPAuthError.cause


code​

readonly code: BearerAuthErrorCode;

错误代码,采用 snake_case 格式。

继承自​

MCPAuthError.code


message​

message: string;

继承自​

MCPAuthError.message


name​

name: string = 'MCPAuthBearerAuthError';

重写自​

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;

  // 捕获 function b 以上的堆栈跟踪
  Error.captureStackTrace(error, b); // 堆栈跟踪中不包含 function 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