Better handle update API errors

This commit is contained in:
Timothy Warren 2021-02-22 15:39:03 -05:00
parent 5498383587
commit 0f9dd61b6b
4 changed files with 18 additions and 6 deletions

View File

@ -144,13 +144,16 @@ abstract class BaseCommand extends Command {
{
if ($fgColor !== NULL)
{
$fgColor = (string)$fgColor;
$fgColor = (int)$fgColor;
}
if ($bgColor !== NULL)
{
$bgColor = (string)$bgColor;
$bgColor = (int)$bgColor;
}
// Colorize the CLI output
// the documented type for the function is wrong
// @phpstan-ignore-next-line
$message = Colors::colorize($message, $fgColor, $bgColor);
$this->getConsole()->writeln($message);
}

View File

@ -16,6 +16,7 @@
namespace Aviat\AnimeClient\Command;
use Aviat\Ion\JsonException;
use ConsoleKit\Widgets;
use Aviat\AnimeClient\API\{
@ -288,7 +289,15 @@ final class SyncLists extends BaseCommand {
// This uses a static so I don't have to fetch this list twice for a count
if ($list[$type] === NULL)
{
$list[$type] = $this->anilistModel->getSyncList(strtoupper($type));
try
{
$list[$type] = $this->anilistModel->getSyncList(strtoupper($type));
}
catch (JsonException)
{
$this->echoErrorBox('Anlist API exception. Can not sync.');
die();
}
}
return $list[$type];
@ -599,7 +608,7 @@ final class SyncLists extends BaseCommand {
$kitsuItem['data']['ratingTwenty'] !== 0
)
{
$update['data']['ratingTwenty'] = $kitsuItem['data']['ratingTwenty'];
$update['data']['ratingTwenty'] = $kitsuItem['data']['rating'];
$return['updateType'][] = Enum\API::ANILIST;
}
else if($dateDiff === self::ANILIST_GREATER && $anilistItem['data']['rating'] !== 0)

View File

@ -228,7 +228,7 @@ final class Anime extends BaseController {
$postData = $transformer->untransform($data);
$fullResult = $this->model->updateLibraryItem(FormItem::from($postData));
if ($fullResult['statusCode'] === 200)
if ($fullResult['statusCode'] === 200 && $fullResult['body']['error'] === NULL)
{
$this->setFlashMessage('Successfully updated.', 'success');
$this->cache->clear();

View File

@ -229,7 +229,7 @@ final class Manga extends Controller {
$post_data = $transformer->untransform($data);
$full_result = $this->model->updateLibraryItem(FormItem::from($post_data));
if ($full_result['statusCode'] === 200)
if ($full_result['statusCode'] === 200 && $full_result['body']['error'] === NULL)
{
$this->setFlashMessage('Successfully updated manga.', 'success');
$this->cache->clear();