-
app/Exceptions/ApiKeyNotFoundException.php
Open in GitHubuse App\Models\ApiKey; use Exception; class ApiKeyNotFoundException extends Exception { public function __construct() { parent::__construct('No available API key found with remaining requests'); } /** * @throws ApiKeyNotFoundException */ public static function validateApiKey(ApiKey|null $apiKey): void { if (!$apiKey || $apiKey->request_remaining <= 0) { throw new self(); } } }
-
app/Jobs/GetJobData.php
Open in GitHubuse App\DTO\JobResponseDTO; use App\Enums\ApiName; use App\Exceptions\ApiKeyNotFoundException; use App\Exceptions\CategoryNotFoundException; use App\Models\ApiKey; use Illuminate\Support\Facades\Log; class GetJobData implements ShouldQueue { // ... public function handle(): void { try { $apiKey = ApiKey::query() ->where('api_name', ApiName::JOB) ->orderByDesc('request_remaining') ->first(); ApiKeyNotFoundException::validateApiKey($apiKey); $categories = JobCategory::all(); CategoryNotFoundException::throwIfNotFound($categories); foreach ($categories as $category) { $this->fetchAndStoreJobs($apiKey, $category); } } catch (ApiKeyNotFoundException|CategoryNotFoundException|\Exception $e) { Log::error('Error on job fetching', [ 'message' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile(), ]); } } // ... }