Genkit JS API reference
    Preparing search index...

    Class UserFacingError

    Creates a new class of Error for issues to be returned to users. Using this error allows a web framework handler (e.g. express, next) to know it is safe to return the message in a request. Other kinds of errors will result in a generic 500 message to avoid the possibility of internal exceptions being leaked to attackers. In JSON requests, code will be an HTTP code and error will be a response body. In streaming requests, { code, message } will be passed as the error message.

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • status:
            | "OK"
            | "CANCELLED"
            | "UNKNOWN"
            | "INVALID_ARGUMENT"
            | "DEADLINE_EXCEEDED"
            | "NOT_FOUND"
            | "ALREADY_EXISTS"
            | "PERMISSION_DENIED"
            | "UNAUTHENTICATED"
            | "RESOURCE_EXHAUSTED"
            | "FAILED_PRECONDITION"
            | "ABORTED"
            | "OUT_OF_RANGE"
            | "UNIMPLEMENTED"
            | "INTERNAL"
            | "UNAVAILABLE"
            | "DATA_LOSS"
      • message: string
      • Optionaldetails: any

      Returns UserFacingError

    Properties

    cause?: unknown
    code: number
    detail?: any
    message: string
    name: string
    originalMessage: string
    responseMetadata?: ErrorResponseMetadata

    Metadata from the HTTP response that triggered this error. Not serialized into the wire format — only available in-process for middleware (e.g. retry) to make informed decisions.

    source?: string
    stack?: string
    status:
        | "OK"
        | "CANCELLED"
        | "UNKNOWN"
        | "INVALID_ARGUMENT"
        | "DEADLINE_EXCEEDED"
        | "NOT_FOUND"
        | "ALREADY_EXISTS"
        | "PERMISSION_DENIED"
        | "UNAUTHENTICATED"
        | "RESOURCE_EXHAUSTED"
        | "FAILED_PRECONDITION"
        | "ABORTED"
        | "OUT_OF_RANGE"
        | "UNIMPLEMENTED"
        | "INTERNAL"
        | "UNAVAILABLE"
        | "DATA_LOSS"
    stackTraceLimit: number

    The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

    The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

    If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

    Methods

    • Returns a JSON-serializable representation of this object.

      Returns HttpErrorWireFormat

    • Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

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

      The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

      The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

      The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

      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();

      Parameters

      • targetObject: object
      • OptionalconstructorOpt: Function

      Returns void