Exceptions
The plugin throws Kirby exceptions in two situations: configuration errors (LogicException) and translation failures (TranslationException).
TranslationException
JohannSchopplich\ContentTranslator\Translation\Exception\TranslationException extends Kirby\Exception\Exception. Built-in strategies throw it when zero units survived – per-unit failures keep the source text and only emit a :warning hook.
final class TranslationException extends \Kirby\Exception\Exception
{
protected static string $defaultKey = 'content-translator.translation';
protected static int $defaultHttpCode = 502;
public function __construct(
string $strategy,
string $reason,
int $unitsAttempted,
int $unitsTranslated = 0,
);
}
Details Payload
The exception carries structured details for logging:
deepl, copilot-ai, or your own).0 when this exception is thrown.For per-unit error context, listen to content-translator.translate:warning – it fires for each failed unit with the underlying Throwable before the strategy decides whether enough units survived.
Catching
use JohannSchopplich\ContentTranslator\Translation\Exception\TranslationException;
try {
$translator->translateContent('de', 'de', 'en');
} catch (TranslationException $error) {
$details = $error->getDetails();
// ['strategy' => 'deepl', 'unitsAttempted' => 12, 'unitsTranslated' => 0]
}
The default HTTP code 502 surfaces when an unhandled TranslationException bubbles up through the Panel.
LogicException
Configuration errors throw Kirby\Exception\LogicException:
| Trigger | Message |
|---|---|
'strategy' => 'ai' without kirby-copilot installed | Strategy "ai" requires the kirby-copilot plugin |
'strategy' => 'banana' | Unknown strategy "banana" |
AuthException
Kirby\Exception\AuthException is thrown for missing API keys:
| Trigger | Message |
|---|---|
| Missing DeepL API key | Missing DeepL API key |
| Missing Copilot AI provider API key | Missing API key in "johannschopplich.copilot.providers.<name>.apiKey" |