Fix: Add graceful handling for unconfigured state, fix 500 error on unconfigured plugin
This commit is contained in:
@@ -5,8 +5,12 @@ declare(strict_types=1);
|
||||
namespace OCA\AnalyticsHub\Controller\Admin;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\IConfig;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
|
||||
use OCA\AnalyticsHub\AppInfo\Application;
|
||||
use OCA\AnalyticsHub\Service\GoogleAnalyticsService;
|
||||
use OCA\AnalyticsHub\Service\LLMService;
|
||||
|
||||
/**
|
||||
* Admin Settings Controller
|
||||
@@ -17,10 +21,22 @@ use OCA\AnalyticsHub\AppInfo\Application;
|
||||
class PageController extends Controller {
|
||||
|
||||
private $appName;
|
||||
private $config;
|
||||
private $gaService;
|
||||
private $llmService;
|
||||
|
||||
public function __construct(string $appName, IRequest $request) {
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
IConfig $config,
|
||||
GoogleAnalyticsService $gaService,
|
||||
LLMService $llmService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->appName = $appName;
|
||||
$this->config = $config;
|
||||
$this->gaService = $gaService;
|
||||
$this->llmService = $llmService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,10 +46,40 @@ class PageController extends Controller {
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index(): TemplateResponse {
|
||||
// Check configuration status gracefully
|
||||
$isConfigured = false;
|
||||
$isGAConfigured = false;
|
||||
$isLLMConfigured = false;
|
||||
|
||||
try {
|
||||
$isGAConfigured = $this->gaService->isConfigured();
|
||||
$isLLMConfigured = $this->llmService->isConfigured();
|
||||
$isConfigured = $isGAConfigured && $isLLMConfigured;
|
||||
} catch (\Exception $e) {
|
||||
// If service initialization fails, app is not configured
|
||||
$isConfigured = false;
|
||||
}
|
||||
|
||||
// Get configuration values (masked for secrets)
|
||||
$clientId = $this->config->getAppValue('google_client_id', Application::APP_NAME, '');
|
||||
$apiKey = $this->config->getAppValue('anthropic_api_key', Application::APP_NAME, '');
|
||||
|
||||
// Mask API key for display
|
||||
$maskedApiKey = '';
|
||||
if (!empty($apiKey)) {
|
||||
$maskedApiKey = substr($apiKey, 0, 8) . '...' . substr($apiKey, -4);
|
||||
}
|
||||
|
||||
return new TemplateResponse($this->appName, 'admin', [
|
||||
'app_name' => $this->appName,
|
||||
'version' => Application::APP_VERSION,
|
||||
'status' => 'Ready for development',
|
||||
'is_configured' => $isConfigured,
|
||||
'is_ga_configured' => $isGAConfigured,
|
||||
'is_llm_configured' => $isLLMConfigured,
|
||||
'google_client_id' => $clientId,
|
||||
'anthropic_api_key_masked' => $maskedApiKey,
|
||||
'request' => $this->request,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user