Skip to main content
Version: Current

tryOk

@rotorsoft/act-root


@rotorsoft/act-root / act-http/src/webhook / tryOk

Function: tryOk()

tryOk(response, options): Promise<void>

Defined in: libs/act-http/src/webhook/classify.ts:67

If response is 2xx, return. Otherwise, capture the response body (best-effort) and throw a RetryableHttpError (for 5xx) or NonRetryableHttpError (for 3xx/4xx). Collapses the classify-and-throw boilerplate every custom HTTP-like reaction would otherwise write into one line:

.on("OrderConfirmed").do(async (event) => {
const response = await my_sdk.deliver(event);
await try_ok(response, { url: my_sdk.url, label: "my_sdk" });
// ...response was 2xx; continue with downstream work...
});

The webhook helper throws webhook-specific subclasses (WebhookError / NonRetryableWebhookError) for backward compatibility โ€” both extend the generic classes thrown here, so instanceof RetryableHttpError matches both webhook and custom-integration errors uniformly.

Parametersโ€‹

responseโ€‹

Response

optionsโ€‹

TryOkOptions

Returnsโ€‹

Promise<void>