Skip to content

Error Handling

The client uses explicit exception types for n8n and transport failures. Some value-object validation errors use PHP's InvalidArgumentException.

Exception Types

ExceptionParentUsed for
N8nExceptionRuntimeExceptionBase package exception.
RequestExceptionN8nExceptionFailed HTTP requests or invalid n8n API responses.
AuthenticationExceptionRequestExceptionHTTP 401 responses.
ExecutionTimeoutExceptionN8nExceptionPolling exceeded the configured timeout.
InvalidWebhookResponseExceptionN8nExceptionWebhook response claimed JSON but could not be decoded.
InvalidArgumentExceptionPHP SPLInvalid local input such as an empty execution ID or invalid webhook URL.

Webhook Errors

php
use PhpN8n\Client\Exceptions\AuthenticationException;
use PhpN8n\Client\Exceptions\InvalidWebhookResponseException;
use PhpN8n\Client\Exceptions\RequestException;

try {
    $response = $client->webhooks()->trigger($webhook, $request);
} catch (AuthenticationException $exception) {
    // n8n returned 401.
} catch (InvalidWebhookResponseException $exception) {
    // Response Content-Type looked like JSON, but the body was invalid JSON.
} catch (RequestException $exception) {
    // HTTP error response or PSR-18 client failure.
    $httpResponse = $exception->response();
}

Webhook behavior:

SituationException
HTTP status 401AuthenticationException
HTTP status >= 400RequestException
PSR-18 client throws ClientExceptionInterfaceRequestException
JSON request body cannot be encodedRequestException
JSON webhook response cannot be decodedInvalidWebhookResponseException

Execution Tracking Errors

php
use PhpN8n\Client\Exceptions\AuthenticationException;
use PhpN8n\Client\Exceptions\ExecutionTimeoutException;
use PhpN8n\Client\Exceptions\RequestException;

try {
    $result = $client->executions()->wait($reference, $polling);
} catch (AuthenticationException $exception) {
    // n8n API key is missing, invalid, or rejected.
} catch (ExecutionTimeoutException $exception) {
    $reference = $exception->reference();
} catch (RequestException $exception) {
    $httpResponse = $exception->response();
}

Execution behavior:

SituationException
executions() called without ApiConfigN8nException
HTTP status 401AuthenticationException
HTTP status >= 400RequestException
PSR-18 client throws ClientExceptionInterfaceRequestException
n8n execution response is invalid JSONRequestException
n8n execution response is not a JSON objectRequestException
Polling timeout reachedExecutionTimeoutException

Validation Errors

Local validation uses InvalidArgumentException.

php
use PhpN8n\Client\Executions\ExecutionReference;

ExecutionReference::fromId(''); // throws InvalidArgumentException

Examples:

InputValidation
Empty webhook URLInvalid.
Webhook URL without hostInvalid.
Webhook URL with unsupported schemeInvalid.
Unsupported webhook method stringInvalid.
Empty execution reference IDInvalid.
Negative polling timeout or intervalInvalid.
Text body with non-string valueInvalid.
Stream body without a PSR-7 streamInvalid.

Keep HTTP Policy In Your HTTP Client

Retries, proxy configuration, TLS options, and connection timeouts are not hard-coded by php-n8n/client.

Configure them in the PSR-18 HTTP client you choose. This keeps the package small and avoids surprising global behavior.

Released under the MIT License.