Log connectiong problems while fetching data from appstore

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2017-05-11 17:46:41 -05:00
parent d83f1d96d4
commit c90d832ce4
3 changed files with 24 additions and 6 deletions

View File

@ -26,23 +26,27 @@ use OC\Files\AppData\Factory;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
class AppFetcher extends Fetcher { class AppFetcher extends Fetcher {
/** /**
* @param Factory $appDataFactory * @param Factory $appDataFactory
* @param IClientService $clientService * @param IClientService $clientService
* @param ITimeFactory $timeFactory * @param ITimeFactory $timeFactory
* @param IConfig $config; * @param IConfig $config
* @param ILogger $logger
*/ */
public function __construct(Factory $appDataFactory, public function __construct(Factory $appDataFactory,
IClientService $clientService, IClientService $clientService,
ITimeFactory $timeFactory, ITimeFactory $timeFactory,
IConfig $config) { IConfig $config,
ILogger $logger) {
parent::__construct( parent::__construct(
$appDataFactory, $appDataFactory,
$clientService, $clientService,
$timeFactory, $timeFactory,
$config $config,
$logger
); );
$this->fileName = 'apps.json'; $this->fileName = 'apps.json';

View File

@ -25,6 +25,7 @@ use OC\Files\AppData\Factory;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
class CategoryFetcher extends Fetcher { class CategoryFetcher extends Fetcher {
/** /**
@ -32,16 +33,19 @@ class CategoryFetcher extends Fetcher {
* @param IClientService $clientService * @param IClientService $clientService
* @param ITimeFactory $timeFactory * @param ITimeFactory $timeFactory
* @param IConfig $config * @param IConfig $config
* @param ILogger $logger
*/ */
public function __construct(Factory $appDataFactory, public function __construct(Factory $appDataFactory,
IClientService $clientService, IClientService $clientService,
ITimeFactory $timeFactory, ITimeFactory $timeFactory,
IConfig $config) { IConfig $config,
ILogger $logger) {
parent::__construct( parent::__construct(
$appDataFactory, $appDataFactory,
$clientService, $clientService,
$timeFactory, $timeFactory,
$config $config,
$logger
); );
$this->fileName = 'categories.json'; $this->fileName = 'categories.json';
$this->endpointUrl = 'https://apps.nextcloud.com/api/v1/categories.json'; $this->endpointUrl = 'https://apps.nextcloud.com/api/v1/categories.json';

View File

@ -22,12 +22,14 @@
namespace OC\App\AppStore\Fetcher; namespace OC\App\AppStore\Fetcher;
use OC\Files\AppData\Factory; use OC\Files\AppData\Factory;
use GuzzleHttp\Exception\ConnectException;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData; use OCP\Files\IAppData;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
abstract class Fetcher { abstract class Fetcher {
const INVALIDATE_AFTER_SECONDS = 300; const INVALIDATE_AFTER_SECONDS = 300;
@ -40,6 +42,8 @@ abstract class Fetcher {
protected $timeFactory; protected $timeFactory;
/** @var IConfig */ /** @var IConfig */
protected $config; protected $config;
/** @var Ilogger */
protected $logger;
/** @var string */ /** @var string */
protected $fileName; protected $fileName;
/** @var string */ /** @var string */
@ -52,15 +56,18 @@ abstract class Fetcher {
* @param IClientService $clientService * @param IClientService $clientService
* @param ITimeFactory $timeFactory * @param ITimeFactory $timeFactory
* @param IConfig $config * @param IConfig $config
* @param ILogger $logger
*/ */
public function __construct(Factory $appDataFactory, public function __construct(Factory $appDataFactory,
IClientService $clientService, IClientService $clientService,
ITimeFactory $timeFactory, ITimeFactory $timeFactory,
IConfig $config) { IConfig $config,
ILogger $logger) {
$this->appData = $appDataFactory->get('appstore'); $this->appData = $appDataFactory->get('appstore');
$this->clientService = $clientService; $this->clientService = $clientService;
$this->timeFactory = $timeFactory; $this->timeFactory = $timeFactory;
$this->config = $config; $this->config = $config;
$this->logger = $logger;
} }
/** /**
@ -153,6 +160,9 @@ abstract class Fetcher {
$responseJson = $this->fetch($ETag, $content); $responseJson = $this->fetch($ETag, $content);
$file->putContent(json_encode($responseJson)); $file->putContent(json_encode($responseJson));
return json_decode($file->getContent(), true)['data']; return json_decode($file->getContent(), true)['data'];
} catch (ConnectException $e) {
$this->logger->logException($e, ['app' => 'appstoreFetcher']);
return [];
} catch (\Exception $e) { } catch (\Exception $e) {
return []; return [];
} }