-
-
Notifications
You must be signed in to change notification settings - Fork 0
Errors
Reference for all exceptions and HTTP status codes used by the Teamleader SDK.
The SDK maps every API response and connection failure to a typed PHP exception. Each exception extends TeamleaderException, so you can catch broadly or narrow down to specific conditions.
Whether exceptions are thrown is controlled by the throw_exceptions flag in config/teamleader.php. One exception to this rule: RateLimitExceededException (429) always throws, regardless of that setting, because silently swallowing a rate-limit failure returns empty data to the caller with no indication of why.
| HTTP Status | Exception Class | Retryable | Log Level |
|---|---|---|---|
| 400 | TeamleaderException |
β | warning |
| 401 | AuthenticationException |
β | error |
| 403 | AuthorizationException |
β | warning |
| 404 | NotFoundException |
β | info |
| 422 | ValidationException |
β | warning |
| 429 | RateLimitExceededException |
β (manual) | warning |
| 500 | ServerException |
β (auto) | critical |
| 502 | ServerException |
β (auto) | critical |
| 503 | ServerException |
β (auto) | critical |
| 504 | ServerException |
β (auto) | critical |
| 0 | ConnectionException |
β (auto) | error |
| β | ConfigurationException |
β | critical |
Exception: TeamleaderException
The request was malformed. Common causes: missing required fields, wrong data types, invalid JSON, malformed dates.
use McoreServices\TeamleaderSDK\Exceptions\TeamleaderException;
try {
$company = Teamleader::companies()->create($data);
} catch (TeamleaderException $e) {
if ($e->getCode() === 400) {
Log::error('Bad request', ['errors' => $e->getAllErrors()]);
}
}Exception: AuthenticationException
Token is missing, expired, or invalid. The SDK handles token refresh automatically before requests. If this exception is thrown, the refresh itself has failed.
use McoreServices\TeamleaderSDK\Exceptions\AuthenticationException;
try {
$companies = Teamleader::companies()->list();
} catch (AuthenticationException $e) {
// Re-authenticate via OAuth flow
return redirect(Teamleader::authorize());
}Exception: AuthorizationException
The authenticated user does not have the required scopes or permissions for this operation.
use McoreServices\TeamleaderSDK\Exceptions\AuthorizationException;
try {
$invoice = Teamleader::invoices()->create($data);
} catch (AuthorizationException $e) {
Log::warning('Insufficient permissions', ['message' => $e->getMessage()]);
}Exception: NotFoundException
The requested resource does not exist, or the UUID is incorrect.
use McoreServices\TeamleaderSDK\Exceptions\NotFoundException;
try {
$contact = Teamleader::contacts()->info('contact-uuid');
} catch (NotFoundException $e) {
// Resource does not exist β handle gracefully
return null;
}Exception: ValidationException
The API rejected the request due to invalid field values. Call getAllErrors() to retrieve the full list of validation messages.
use McoreServices\TeamleaderSDK\Exceptions\ValidationException;
try {
$deal = Teamleader::deals()->create($data);
} catch (ValidationException $e) {
$errors = $e->getAllErrors(); // array of error strings
return back()->withErrors($errors);
}Exception: RateLimitExceededException
Always thrown, regardless of the throw_exceptions configuration flag.
The exception carries:
-
getRetryAfter()β seconds to wait before retrying (fromRetry-Afterheader, defaults to 60) -
getResetTime()β Unix timestamp when the rate limit resets (fromX-RateLimit-Resetheader)
The SDK's built-in retry logic does not automatically retry 429 responses. Sleeping for 60 seconds inside a queue worker blocks the thread. Handle this at the job/queue level instead.
use McoreServices\TeamleaderSDK\Exceptions\RateLimitExceededException;
try {
$invoices = Teamleader::invoices()->list();
} catch (RateLimitExceededException $e) {
$retryAfter = $e->getRetryAfter(); // seconds
// Delay and re-dispatch rather than sleeping inline
dispatch(new FetchInvoicesJob())->delay(now()->addSeconds($retryAfter));
}Exception: ServerException
Covers 500, 502, 503, and 504. These are transient Teamleader-side failures. The SDK automatically retries server errors using exponential backoff.
use McoreServices\TeamleaderSDK\Exceptions\ServerException;
try {
$result = Teamleader::deals()->create($data);
} catch (ServerException $e) {
// Retries exhausted β queue for later
dispatch(new CreateDealJob($data))->delay(now()->addMinutes(5));
}Exception: ConnectionException
Thrown when the HTTP request cannot be completed. Common causes: network unavailability, DNS failure, SSL handshake failure, firewall blocking.
use McoreServices\TeamleaderSDK\Exceptions\ConnectionException;
try {
$companies = Teamleader::companies()->list();
} catch (ConnectionException $e) {
Log::error('Teamleader unreachable', ['message' => $e->getMessage()]);
}Exception: ConfigurationException
Thrown during SDK initialisation when required credentials or settings are missing. Logged at critical level.
Catch specific exceptions before broad ones. TeamleaderException is the base class for all SDK exceptions.
use McoreServices\TeamleaderSDK\Exceptions\{
AuthenticationException,
ValidationException,
RateLimitExceededException,
NotFoundException,
ServerException,
ConnectionException,
TeamleaderException
};
try {
$result = Teamleader::companies()->create($data);
} catch (ValidationException $e) {
// Fix input and retry β do not queue
return back()->withErrors($e->getAllErrors());
} catch (AuthenticationException $e) {
// Re-authenticate
return redirect(Teamleader::authorize());
} catch (RateLimitExceededException $e) {
// Re-dispatch after delay β do not sleep inline
dispatch(new CreateCompanyJob($data))->delay(now()->addSeconds($e->getRetryAfter()));
} catch (NotFoundException $e) {
// Resource gone β handle gracefully
return null;
} catch (ServerException | ConnectionException $e) {
// Transient β queue for retry
dispatch(new CreateCompanyJob($data))->delay(now()->addMinutes(5));
} catch (TeamleaderException $e) {
// Unexpected error
Log::error('Teamleader error', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
}// config/teamleader.php
'error_handling' => [
'throw_exceptions' => true, // false = log only (except 429, which always throws)
],- Filtering β Filter parameters and validation
- Sideloading β Loading related data
- Usage β General SDK usage guide
Last Updated: August 2026 β’ SDK Version: 2.2.2 β’ Made with β€οΈ by MCore Services
- Departments
- Users
- Teams
- Custom Fields
- Work Types
- Document Templates
- Currencies
- Notes
- Email Tracking
- Closing Days
- Day Off Types
- Days Off
- User Schedules
- Invoices
- Credit Notes
- Subscriptions
- Payment Methods
- Payment Terms
- Tax Rates
- Withholding Tax Rates
- Commercial Discounts
Next Gen Projects
Legacy Projects