Gordian Envelope TypeScript Library - v1.0.0-alpha.13
    Preparing search index...

    Class Response

    A Response represents a reply to a Request containing either a successful result or an error.

    import { Response, ARID } from '@bcts/envelope';

    // Create a request ID (normally this would come from the original request)
    const requestId = ARID.new();

    // Create a successful response
    const successResponse = Response.newSuccess(requestId)
    .withResult("Transaction completed");

    // Create an error response
    const errorResponse = Response.newFailure(requestId)
    .withError("Insufficient funds");

    // Convert to envelopes
    const successEnvelope = successResponse.toEnvelope();
    const errorEnvelope = errorResponse.toEnvelope();

    Implements

    Index

    Methods

    • Creates a new successful response with the specified request ID.

      By default, the result will be the 'OK' known value. Use withResult to set a specific result value.

      Parameters

      • id: ARID

      Returns Response

    • Creates a new failure response with the specified request ID.

      By default, the error will be the 'Unknown' known value. Use withError to set a specific error message.

      Parameters

      • id: ARID

      Returns Response

    • Creates a new early failure response without a request ID.

      An early failure occurs when the error happens before the request has been fully processed, so the request ID is not known.

      Returns Response

    • Extracts a typed result value from a successful response.

      Type Parameters

      • T

      Parameters

      • decoder: (cbor: unknown) => T

      Returns T

    • Extracts a typed error value from a failure response.

      Type Parameters

      • T

      Parameters

      • decoder: (cbor: unknown) => T

      Returns T