Skip to content

Commit

Permalink
Added default exception handler fallback for PutCuratorReviewImport.
Browse files Browse the repository at this point in the history
CI now responds with:
  HTTP server responded with error: 500 "Internal Server Error".
  {"success":25,"clanid":32686107}
  • Loading branch information
Bilge committed Nov 15, 2023
1 parent 407c5d6 commit 1846ee6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
36 changes: 36 additions & 0 deletions src/Import/PutCuratorReviewExceptionHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);

namespace ScriptFUSION\Steam250\Curator\Import;

use ScriptFUSION\Porter\Connector\Recoverable\ExponentialAsyncDelayRecoverableExceptionHandler;
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableException;
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableExceptionHandler;
use ScriptFUSION\Porter\Net\Http\HttpServerException;
use ScriptFUSION\Retry\ExceptionHandler\AsyncExponentialBackoffExceptionHandler;

final class PutCuratorReviewExceptionHandler implements RecoverableExceptionHandler
{
private RecoverableExceptionHandler $exceptionHandler;

public function initialize(): void
{
$this->exceptionHandler = new ExponentialAsyncDelayRecoverableExceptionHandler(
// Wait at least a minute before trying again.
600 * AsyncExponentialBackoffExceptionHandler::DEFAULT_COEFFICIENT
);
$this->exceptionHandler->initialize();
}

public function __invoke(RecoverableException $exception): void
{
if ($exception instanceof HttpServerException && $exception->getCode() === 400) {
$response = \json_decode($exception->getResponse()->getBody());
if ($response->success === 8) {
throw new \RuntimeException('Invalid param: app probably deleted.');
}
}

($this->exceptionHandler)($exception);
}
}
16 changes: 2 additions & 14 deletions src/Import/PutCuratorReviewImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

namespace ScriptFUSION\Steam250\Curator\Import;

use ScriptFUSION\Porter\Connector\Recoverable\RecoverableException;
use ScriptFUSION\Porter\Connector\Recoverable\StatelessRecoverableExceptionHandler;
use ScriptFUSION\Porter\Import\Import;
use ScriptFUSION\Porter\Net\Http\HttpServerException;
use ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorReview;
use ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorSession;
use ScriptFUSION\Porter\Provider\Steam\Resource\Curator\PutCuratorReview;
Expand All @@ -17,6 +14,7 @@ final class PutCuratorReviewImport extends Import
{
private const LANG = 'en';


public function __construct(CuratorSession $session, int $curatorId, array $app)
{
$number = new \NumberFormatter(self::LANG, \NumberFormatter::DEFAULT_STYLE);
Expand All @@ -43,16 +41,6 @@ public function __construct(CuratorSession $session, int $curatorId, array $app)
))->setUrl("https://steam250.com{$ranking->getUrlPath()}#app/$app[app_id]/" . rawurlencode($app['name']))
));

$this->setRecoverableExceptionHandler(new StatelessRecoverableExceptionHandler($this->handleException(...)));
}

private function handleException(RecoverableException $exception): void
{
if ($exception instanceof HttpServerException && $exception->getCode() === 400) {
$response = \json_decode($exception->getResponse()->getBody());
if ($response->success === 8) {
throw new \RuntimeException('Invalid param: app probably deleted.');
}
}
$this->setRecoverableExceptionHandler(new PutCuratorReviewExceptionHandler);
}
}

0 comments on commit 1846ee6

Please sign in to comment.