Documentation
    Preparing search index...

    Function httpError

    • Validates that a function throws an HTTP error with specific status codes.

      Specialized error validator for HTTP operations. Validates that the function throws an HttpError with one of the specified status codes. Useful for testing API endpoints, authentication, and authorization logic.

      Processing cost: The task is invoked once. Classification reads the thrown shape once and scans the expected status list until a match, using O(S) worst-case status comparisons and constant auxiliary state.

      Reuse: Each invocation must evaluate its supplied task or request to observe current behavior; prior results cannot replace these effectful checks.

      Resource ownership: The returned promise retains invocation-local state until settlement. The callback owns its external resources, and this validator provides no cancellation or timeout.

      Type Parameters

      • T

      Parameters

      • title: string

        Descriptive title used in error messages

      • status: number | number[]

        Expected status code(s), can be a single number or array

      • task: () => T

        The function that should throw an HttpError

      Returns T extends Promise<any> ? Promise<void> : void

      Void or Promise based on the input type

      // Validate 401 Unauthorized
      await TestValidator.httpError(
      "should return 401 for invalid token",
      401,
      async () =>
      await api.functional.getProtectedResource("invalid-token"),
      );

      // Validate multiple possible error codes
      await TestValidator.httpError(
      "should return client error",
      [400, 404, 422],
      async () => await api.functional.updateNonexistentResource(data),
      );

      // Validate server errors
      TestValidator.httpError(
      "should handle server errors",
      [500, 502, 503],
      () => callFaultyEndpoint(),
      );

      Error when function doesn't throw HttpError or status code doesn't match

      contracts/common.md#principled-implementation The thrown value must expose a constructor named HttpError and one expected numeric status, matched by name because generated SDKs define their own classes. Missing or throwing properties make classification fail instead of escaping the expectation. The returned promise chain propagates rejection-handler failures without leaving a separately bridged promise pending.

      contracts/common.md#clear-and-simple-design One predicate reads the thrown value once and is shared by the synchronous and asynchronous paths; asynchronous settlement uses the task's own promise chain.

      contracts/common.md#prohibited-implementation-shortcuts The check follows the documented error shape, not a specific SDK or status list.

      contracts/common.md#meaningful-documentation The comment documents the status argument, the two task kinds, and the thrown error, with examples.