Make Kitsu auth token error easier to recover from
All checks were successful
timw4mail/HummingBirdAnimeClient/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2022-01-06 12:50:26 -05:00
parent ecf09b5641
commit c23001e7b1
2 changed files with 9 additions and 3 deletions

View File

@ -44,6 +44,7 @@ use Aviat\Ion\{
use Generator; use Generator;
use function Amp\Promise\wait; use function Amp\Promise\wait;
use function Aviat\AnimeClient\getApiClient; use function Aviat\AnimeClient\getApiClient;
use const Aviat\AnimeClient\SESSION_SEGMENT;
/** /**
* Kitsu API Model * Kitsu API Model
@ -707,9 +708,14 @@ final class Model {
$rawData = Json::decode($json); $rawData = Json::decode($json);
$data = $rawData['data']['findProfileBySlug']['library']['all'] ?? []; $data = $rawData['data']['findProfileBySlug']['library']['all'] ?? [];
$page = $data['pageInfo']; $page = $data['pageInfo'] ?? [];
if (empty($data)) if (empty($data))
{ {
// Clear session, in case the error is an invalid token.
$segment = $this->container->get('session')
->getSegment(SESSION_SEGMENT);
$segment->clear();
// @TODO Proper Error logging // @TODO Proper Error logging
dump($rawData); dump($rawData);
die(); die();
@ -719,7 +725,7 @@ final class Model {
yield $emit($data['nodes']); yield $emit($data['nodes']);
if ($page['hasNextPage'] === FALSE) if ($page['hasNextPage'] !== TRUE)
{ {
break; break;
} }

View File

@ -136,7 +136,7 @@ final class AnimeTransformer extends AbstractTransformer {
'show_type' => $base['subtype'], 'show_type' => $base['subtype'],
'status' => Kitsu::getAiringStatus($base['startDate'], $base['endDate']), 'status' => Kitsu::getAiringStatus($base['startDate'], $base['endDate']),
'streaming_links' => Kitsu::parseStreamingLinks($base['streamingLinks']['nodes'] ?? []), 'streaming_links' => Kitsu::parseStreamingLinks($base['streamingLinks']['nodes'] ?? []),
'synopsis' => $base['description']['en'], 'synopsis' => $base['description']['en'] ?? '',
'title' => $title, 'title' => $title,
'titles' => $titles, 'titles' => $titles,
'titles_more' => $titles_more, 'titles_more' => $titles_more,