KnpLabs / packagist-api

PHP API for Packagist
MIT License
182 stars 46 forks source link

[2.x] Calling a non-existent package returns an InvalidArgumentException (invalid data), previously a GuzzleException #82

Closed robbieaverill closed 2 years ago

robbieaverill commented 2 years ago

Test script:

<?php

require __DIR__ . '/../vendor/autoload.php';

$client = new Packagist\Api\Client();
$package = $client->get('i-do/not-exist');

var_export($package);

In v1.7.2 running this throws a Guzzle exception:

PHP Fatal error:  Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET https://packagist.org/packages/i-do/not-exist.json` resulted in a `404 Not Found` response:
{"status":"error","message":"Package not found"}

In 2.x-dev it throws an InvalidArgumentException:

PHP Fatal error:  Uncaught InvalidArgumentException: Invalid input data. in .../src/Packagist/Api/Result/Factory.php:56

We can throw a specific exception when we encounter this, which devs can use to detect a 404 on packages.