Skip to content

Error Handling

The package throws specific exceptions for different error scenarios. All exceptions extend Rollogi\LaravelHubspot\Exceptions\HubSpotException.

Exception Types

ExceptionHTTP StatusDescription
NotFoundException404Resource not found
InvalidRequestException400 / 409Bad request or conflict
RateLimitException429Rate limit exceeded (after automatic retry failed)
MethodNotAllowedException405Method not allowed
InvalidWebhookSignatureException403Webhook signature verification failed

Webhook Signature Errors

InvalidWebhookSignatureException is thrown by the webhook middleware when signature verification fails. It self-renders as a JSON response. See the Webhooks page for more details on webhook signature verification.

Handling Exceptions

php
use Rollogi\LaravelHubspot\Crm\Contact;
use Rollogi\LaravelHubspot\Exceptions\InvalidRequestException;
use Rollogi\LaravelHubspot\Exceptions\InvalidWebhookSignatureException;
use Rollogi\LaravelHubspot\Exceptions\MethodNotAllowedException;
use Rollogi\LaravelHubspot\Exceptions\NotFoundException;
use Rollogi\LaravelHubspot\Exceptions\RateLimitException;

try {
    $contact = Contact::findOrFail('nonexistent');
} catch (NotFoundException $exception) {
    // 404 - Resource not found
    $response = $exception->response; // Access the full HTTP response
} catch (InvalidRequestException $exception) {
    // 400 or 409 - Bad request or conflict
} catch (RateLimitException $exception) {
    // 429 - Rate limit exceeded (after automatic retry failed)
    $response = $exception->response;
} catch (MethodNotAllowedException $exception) {
    // 405 - Method not allowed
    $response = $exception->response;
}

Each exception provides access to the full HTTP response via the $exception->response property, allowing you to inspect status codes, headers, and response bodies for debugging.