Descriptive title used in error messages
Expected status code(s), can be a single number or array
The function that should throw an HttpError
Void or Promise
// 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(),
);
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.
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.