MessagingError class

描述傳訊錯誤的基類。

Extends

Error

建構函式

MessagingError(string)

屬性

condition

錯誤條件。

info

服務提供的任何其他錯誤資訊。

name

錯誤名稱。 默認值:「MessagingError」。。

retryable

描述錯誤是否可重試。 默認值:true。

translated

錯誤是否已轉譯。 默認值:true。

繼承的屬性

message
stack
stackTraceLimit

Error.stackTraceLimit 屬性指定堆疊跟蹤收集的堆疊幀數(無論是由 new Error().stack 還是 Error.captureStackTrace(obj)生成)。

默認值為 10 but can be set to any valid JavaScript number. 更改將影響在更改值 捕獲的任何堆疊跟蹤。

如果設置為非數位值或設置為負數,則堆疊跟蹤將不會捕獲任何幀。

繼承的方法

captureStackTrace(object, Function)

在上創建一個 .stack 屬性,該屬性在訪問時返回一個字串,該字串 targetObject表示調用的代碼 Error.captureStackTrace() 中的位置。

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

跟蹤的第一行將以 為 ${myObject.name}: ${myObject.message}前綴。

optional constructorOpt 參數接受一個函數。 如果給定,則 上面的 constructorOpt所有幀 ,包括 constructorOpt,將從生成的堆疊跟蹤中省略。

constructorOpt 參數可用於向使用者隱藏錯誤生成的實現詳細資訊。 例如:

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();
prepareStackTrace(Error, CallSite[])

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

建構函式詳細資料

MessagingError(string)

new MessagingError(message: string)

參數

message

string

提供錯誤詳細信息的錯誤訊息。

屬性詳細資料

condition

錯誤條件。

condition?: string

屬性值

string

info

服務提供的任何其他錯誤資訊。

info?: any

屬性值

any

name

錯誤名稱。 默認值:「MessagingError」。。

name: string

屬性值

string

retryable

描述錯誤是否可重試。 默認值:true。

retryable: boolean

屬性值

boolean

translated

錯誤是否已轉譯。 默認值:true。

translated: boolean

屬性值

boolean

繼承的屬性詳細資料

message

message: string

屬性值

string

繼承自 Error.message

stack

stack?: string

屬性值

string

繼承自 Error.stack

stackTraceLimit

Error.stackTraceLimit 屬性指定堆疊跟蹤收集的堆疊幀數(無論是由 new Error().stack 還是 Error.captureStackTrace(obj)生成)。

默認值為 10 but can be set to any valid JavaScript number. 更改將影響在更改值 捕獲的任何堆疊跟蹤。

如果設置為非數位值或設置為負數,則堆疊跟蹤將不會捕獲任何幀。

static stackTraceLimit: number

屬性值

number

繼承自 Error.stackTraceLimit

繼承的方法的詳細資料

captureStackTrace(object, Function)

在上創建一個 .stack 屬性,該屬性在訪問時返回一個字串,該字串 targetObject表示調用的代碼 Error.captureStackTrace() 中的位置。

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

跟蹤的第一行將以 為 ${myObject.name}: ${myObject.message}前綴。

optional constructorOpt 參數接受一個函數。 如果給定,則 上面的 constructorOpt所有幀 ,包括 constructorOpt,將從生成的堆疊跟蹤中省略。

constructorOpt 參數可用於向使用者隱藏錯誤生成的實現詳細資訊。 例如:

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();
static function captureStackTrace(targetObject: object, constructorOpt?: Function)

參數

targetObject

object

constructorOpt

Function

繼承自 Error.captureStackTrace

prepareStackTrace(Error, CallSite[])

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

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

參數

err

Error

stackTraces

CallSite[]

傳回

any

繼承自 Error.prepareStackTrace