Improve error logging
This commit is contained in:
parent
65a8da755a
commit
e7e70a1541
@ -20,37 +20,37 @@ use Aviat\AnimeClient\Types\AbstractType;
|
||||
|
||||
class MediaListEntry extends AbstractType {
|
||||
/**
|
||||
* @var int
|
||||
* @var int|string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
public $notes;
|
||||
public ?string $notes;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $private;
|
||||
public ?bool $private;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $progress;
|
||||
public int $progress;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $repeat;
|
||||
public ?int $repeat;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $status;
|
||||
public string $status;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $score;
|
||||
public ?int $score;
|
||||
}
|
@ -98,8 +98,11 @@ final class Model {
|
||||
|
||||
if (array_key_exists('error', $data))
|
||||
{
|
||||
dump($data['error']);
|
||||
dump($response);
|
||||
dump([
|
||||
'method' => __CLASS__ . '\\' . __METHOD__,
|
||||
'error' => $data['error'],
|
||||
'response' => $response,
|
||||
]);
|
||||
die();
|
||||
}
|
||||
|
||||
@ -135,8 +138,11 @@ final class Model {
|
||||
|
||||
if (array_key_exists('error', $data))
|
||||
{
|
||||
dump($data['error']);
|
||||
dump($response);
|
||||
dump([
|
||||
'method' => __CLASS__ . '\\' . __METHOD__,
|
||||
'error' => $data['error'],
|
||||
'response' => $response,
|
||||
]);
|
||||
die();
|
||||
}
|
||||
|
||||
|
@ -154,16 +154,12 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
*/
|
||||
public function postRequest(...$args): array
|
||||
{
|
||||
$logger = NULL;
|
||||
if ($this->getContainer())
|
||||
{
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
}
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
|
||||
$response = $this->getResponse('POST', ...$args);
|
||||
$validResponseCodes = [200, 201];
|
||||
|
||||
if ( ! in_array($response->getStatus(), $validResponseCodes, TRUE) && $logger)
|
||||
if ( ! in_array($response->getStatus(), $validResponseCodes, TRUE))
|
||||
{
|
||||
$logger->warning('Non 2xx response for POST api call', $response->getBody());
|
||||
}
|
||||
@ -275,26 +271,17 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
*/
|
||||
public function getResponse(string $type, string $url, array $options = []): Response
|
||||
{
|
||||
$logger = NULL;
|
||||
if ($this->getContainer())
|
||||
{
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
}
|
||||
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
$request = $this->setUpRequest($type, $url, $options);
|
||||
|
||||
$response = getResponse($request);
|
||||
|
||||
if ($logger)
|
||||
{
|
||||
$logger->debug('Kitsu API Response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
'requestHeaders' => $request->getHeaders(),
|
||||
]);
|
||||
}
|
||||
$logger->debug('Kitsu API Response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
'requestHeaders' => $request->getHeaders(),
|
||||
]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
@ -306,12 +293,7 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
*/
|
||||
private function getResponseFromRequest(Request $request): Response
|
||||
{
|
||||
$logger = NULL;
|
||||
if ($this->getContainer())
|
||||
{
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
}
|
||||
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
$response = getResponse($request);
|
||||
|
||||
$logger->debug('Kitsu GraphQL response', [
|
||||
@ -337,24 +319,17 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
$response = $this->getResponse('POST', K::GRAPHQL_ENDPOINT, $options);
|
||||
$validResponseCodes = [200, 201];
|
||||
|
||||
$logger = NULL;
|
||||
if ($this->getContainer())
|
||||
{
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
$logger->debug('Kitsu GraphQL response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
]);
|
||||
}
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
$logger->debug('Kitsu GraphQL response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
]);
|
||||
|
||||
if ( ! \in_array($response->getStatus(), $validResponseCodes, TRUE))
|
||||
{
|
||||
if ($logger !== NULL)
|
||||
{
|
||||
$logger->warning('Non 200 response for GraphQL call', (array)$response->getBody());
|
||||
}
|
||||
$logger->warning('Non 200 response for GraphQL call', (array)$response->getBody());
|
||||
}
|
||||
|
||||
return Json::decode(wait($response->getBody()->buffer()));
|
||||
@ -373,12 +348,7 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
*/
|
||||
private function request(string $type, string $url, array $options = []): array
|
||||
{
|
||||
$logger = NULL;
|
||||
if ($this->getContainer())
|
||||
{
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
}
|
||||
|
||||
$logger = $this->container->getLogger('kitsu-request');
|
||||
$response = $this->getResponse($type, $url, $options);
|
||||
$statusCode = $response->getStatus();
|
||||
|
||||
|
@ -105,7 +105,7 @@ final class SyncLists extends BaseCommand {
|
||||
if ( ! $anilistEnabled)
|
||||
{
|
||||
$this->echoErrorBox('Anlist API is not enabled. Can not sync.');
|
||||
die();
|
||||
exit();
|
||||
}
|
||||
|
||||
// Authentication is required to update Kitsu
|
||||
@ -296,17 +296,7 @@ final class SyncLists extends BaseCommand {
|
||||
{
|
||||
$uType = ucfirst($type);
|
||||
|
||||
$kitsuCount = 0;
|
||||
try
|
||||
{
|
||||
$kitsuCount = $this->kitsuModel->{"get{$uType}ListCount"}();
|
||||
}
|
||||
catch (FailedResponseException $e)
|
||||
{
|
||||
dump($e);
|
||||
}
|
||||
|
||||
return $kitsuCount;
|
||||
return $this->kitsuModel->{"get{$uType}ListCount"}() ?? 0;
|
||||
}
|
||||
|
||||
private function fetchKitsu(string $type): array
|
||||
@ -327,7 +317,10 @@ final class SyncLists extends BaseCommand {
|
||||
|
||||
if ( ! array_key_exists('included', $data))
|
||||
{
|
||||
dump($data);
|
||||
dump([
|
||||
'problem' => 'Missing included data in method ' . __METHOD__,
|
||||
'data' => $data
|
||||
]);
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -742,7 +735,11 @@ final class SyncLists extends BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
dump($responseData);
|
||||
dump([
|
||||
'problem' => 'Failed to update kitsu list item',
|
||||
'syncDate' => $itemsToUpdate[$key],
|
||||
'responseData' => $responseData,
|
||||
]);
|
||||
$verb = ($action === SyncAction::UPDATE) ? SyncAction::UPDATE : SyncAction::CREATE;
|
||||
$this->echoError("Failed to {$verb} Kitsu {$type} list item with id: {$id}");
|
||||
|
||||
@ -799,7 +796,11 @@ final class SyncLists extends BaseCommand {
|
||||
}
|
||||
else
|
||||
{
|
||||
dump($responseData);
|
||||
dump([
|
||||
'problem' => 'Failed to update anilist list item',
|
||||
'syncDate' => $itemsToUpdate[$key],
|
||||
'responseData' => $responseData,
|
||||
]);
|
||||
$verb = ($action === SyncAction::UPDATE) ? SyncAction::UPDATE : SyncAction::CREATE;
|
||||
$this->echoError("Failed to {$verb} Anilist {$type} list item with id: {$id}");
|
||||
}
|
||||
|
@ -77,9 +77,6 @@ final class UpdateThumbnails extends ClearThumbnails {
|
||||
$includes = JsonAPI::organizeIncludes($animeList['included']);
|
||||
$animeIds = array_keys($includes['anime']);
|
||||
|
||||
// print_r($mangaIds);
|
||||
// die();
|
||||
|
||||
return [
|
||||
'anime' => $animeIds,
|
||||
'manga' => $mangaIds,
|
||||
|
@ -267,7 +267,7 @@ final class Anime extends BaseController {
|
||||
if (empty($data))
|
||||
{
|
||||
$this->errorPage(400, 'Bad Request', '');
|
||||
die();
|
||||
exit();
|
||||
}
|
||||
|
||||
$response = $this->model->incrementLibraryItem(FormItem::from($data));
|
||||
|
Loading…
Reference in New Issue
Block a user