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

类:MCPAuthConfigError

当 mcp-auth 配置出现问题时抛出的错误。

继承自

构造函数

构造函数

new MCPAuthConfigError(code: string, message: string): MCPAuthConfigError;

参数

code

string

以 snake_case 格式表示的错误代码。

message

string

对错误的人类可读描述。

返回

MCPAuthConfigError

继承自

MCPAuthError.constructor

属性

cause?

optional cause: unknown;

继承自

MCPAuthError.cause


code

readonly code: string;

以 snake_case 格式表示的错误代码。

继承自

MCPAuthError.code


message

message: string;

继承自

MCPAuthError.message


name

name: string = 'MCPAuthConfigError';

重写自

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)都将从生成的堆栈跟踪中省略。

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