Condividi tramite


RestError class

Errore risultante da una richiesta HTTP a un endpoint di servizio.

Extends

Error

Costruttori

RestError(string, string, number, WebResourceLike, HttpOperationResponse)

Proprietà

code

Codice di errore, se presente. Può essere una delle proprietà del codice di errore statico (REQUEST_SEND_ERROR/PARSE_ERROR) o può essere un codice stringa da una chiamata di sistema sottostante (E_NOENT).

details

Eventuali dettagli aggiuntivi. Nel caso di errori di deserializzazione, può essere la risposta elaborata.

PARSE_ERROR

Stringa costante per identificare gli errori che possono verificarsi dall'analisi di una risposta HTTP in ingresso. In genere indica un corpo HTTP in formato non valido, ad esempio un payload JSON codificato incompleto.

request

Richiesta in uscita.

REQUEST_SEND_ERROR

Stringa costante per identificare gli errori che possono verificarsi durante l'esecuzione di una richiesta HTTP che indica un problema con il livello di trasporto (ad esempio, il nome host dell'URL non può essere risolto tramite DNS).

response

Risposta in ingresso.

statusCode

Codice di stato HTTP della risposta, se ne è stato restituito uno.

Proprietà ereditate

message
name
stack
stackTraceLimit

La Error.stackTraceLimit proprietà specifica il numero di stack frame raccolti da un'analisi dello stack (generata da new Error().stack o Error.captureStackTrace(obj)).

Il valore predefinito è 10 ma può essere impostato su qualsiasi numero JavaScript valido. Le modifiche influiranno su qualsiasi analisi dello stack acquisita dopo la modifica del valore.

Se impostato su un valore diverso da un numero o su un numero negativo, le tracce dello stack non acquisiranno alcun fotogramma.

Metodi ereditati

captureStackTrace(object, Function)

Crea una .stack proprietà in targetObject, che, quando viene effettuato l'accesso, restituisce una stringa che rappresenta la posizione nel codice in cui Error.captureStackTrace() è stata chiamata.

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

La prima riga della traccia sarà preceduta dal ${myObject.name}: ${myObject.message}prefisso .

L'argomento opzionale constructorOpt accetta una funzione. Se specificato, tutti i fotogrammi precedenti constructorOpt, incluso constructorOpt, verranno omessi dall'analisi dello stack generata.

L'argomento constructorOpt è utile per nascondere all'utente i dettagli di implementazione della generazione degli errori. Per esempio:

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[])

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

Dettagli costruttore

RestError(string, string, number, WebResourceLike, HttpOperationResponse)

new RestError(message: string, code?: string, statusCode?: number, request?: WebResourceLike, response?: HttpOperationResponse)

Parametri

message

string

code

string

statusCode

number

request
WebResourceLike

Dettagli proprietà

code

Codice di errore, se presente. Può essere una delle proprietà del codice di errore statico (REQUEST_SEND_ERROR/PARSE_ERROR) o può essere un codice stringa da una chiamata di sistema sottostante (E_NOENT).

code?: string

Valore della proprietà

string

details

Eventuali dettagli aggiuntivi. Nel caso di errori di deserializzazione, può essere la risposta elaborata.

details?: unknown

Valore della proprietà

unknown

PARSE_ERROR

Stringa costante per identificare gli errori che possono verificarsi dall'analisi di una risposta HTTP in ingresso. In genere indica un corpo HTTP in formato non valido, ad esempio un payload JSON codificato incompleto.

static PARSE_ERROR: string

Valore della proprietà

string

request

Richiesta in uscita.

request?: WebResourceLike

Valore della proprietà

REQUEST_SEND_ERROR

Stringa costante per identificare gli errori che possono verificarsi durante l'esecuzione di una richiesta HTTP che indica un problema con il livello di trasporto (ad esempio, il nome host dell'URL non può essere risolto tramite DNS).

static REQUEST_SEND_ERROR: string

Valore della proprietà

string

response

Risposta in ingresso.

response?: HttpOperationResponse

Valore della proprietà

statusCode

Codice di stato HTTP della risposta, se ne è stato restituito uno.

statusCode?: number

Valore della proprietà

number

Dettagli proprietà ereditate

message

message: string

Valore della proprietà

string

Ereditato da Error.message

name

name: string

Valore della proprietà

string

ereditato da Error.name

stack

stack?: string

Valore della proprietà

string

ereditato da Error.stack

stackTraceLimit

La Error.stackTraceLimit proprietà specifica il numero di stack frame raccolti da un'analisi dello stack (generata da new Error().stack o Error.captureStackTrace(obj)).

Il valore predefinito è 10 ma può essere impostato su qualsiasi numero JavaScript valido. Le modifiche influiranno su qualsiasi analisi dello stack acquisita dopo la modifica del valore.

Se impostato su un valore diverso da un numero o su un numero negativo, le tracce dello stack non acquisiranno alcun fotogramma.

static stackTraceLimit: number

Valore della proprietà

number

ereditato da Error.stackTraceLimit

Dettagli dei metodi ereditati

captureStackTrace(object, Function)

Crea una .stack proprietà in targetObject, che, quando viene effettuato l'accesso, restituisce una stringa che rappresenta la posizione nel codice in cui Error.captureStackTrace() è stata chiamata.

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

La prima riga della traccia sarà preceduta dal ${myObject.name}: ${myObject.message}prefisso .

L'argomento opzionale constructorOpt accetta una funzione. Se specificato, tutti i fotogrammi precedenti constructorOpt, incluso constructorOpt, verranno omessi dall'analisi dello stack generata.

L'argomento constructorOpt è utile per nascondere all'utente i dettagli di implementazione della generazione degli errori. Per esempio:

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)

Parametri

targetObject

object

constructorOpt

Function

Ereditato da Error.captureStackTrace

prepareStackTrace(Error, CallSite[])

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

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

Parametri

err

Error

stackTraces

CallSite[]

Restituisce

any

Ereditato da Error.prepareStackTrace