diff --git a/CHANGELOG.md b/CHANGELOG.md index 54484b889..9c7c0f2b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa This project follows [Semantic Versioning](http://semver.org) guidelines. +## v0.7.2 (Derelict Dermodactylus) +### Fixed +* Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint. + ## v0.7.1 (Derelict Dermodactylus) ### Fixed * Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted. diff --git a/app/Http/Requests/Api/Application/ApplicationApiRequest.php b/app/Http/Requests/Api/Application/ApplicationApiRequest.php index 126e6d604..ada9b4b00 100644 --- a/app/Http/Requests/Api/Application/ApplicationApiRequest.php +++ b/app/Http/Requests/Api/Application/ApplicationApiRequest.php @@ -9,6 +9,7 @@ use Illuminate\Foundation\Http\FormRequest; use Pterodactyl\Exceptions\PterodactylException; use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\Routing\Exception\InvalidParameterException; abstract class ApplicationApiRequest extends FormRequest { @@ -76,22 +77,23 @@ abstract class ApplicationApiRequest extends FormRequest } /** - * Grab a model from the route parameters. If no model exists under - * the specified key a default response is returned. + * Grab a model from the route parameters. If no model is found in the + * binding mappings an exception will be thrown. * * @param string $model - * @param mixed $default * @return mixed + * + * @throws \Symfony\Component\Routing\Exception\InvalidParameterException */ - public function getModel(string $model, $default = null) + public function getModel(string $model) { $parameterKey = array_get(array_flip(ApiSubstituteBindings::getMappings()), $model); - if (! is_null($parameterKey)) { - $model = $this->route()->parameter($parameterKey); + if (is_null($parameterKey)) { + throw new InvalidParameterException; } - return $model ?? $default; + return $this->route()->parameter($parameterKey); } /* diff --git a/app/Http/Requests/Api/Application/Nests/Eggs/GetEggRequest.php b/app/Http/Requests/Api/Application/Nests/Eggs/GetEggRequest.php index b3f1a08a0..fb364d1ae 100644 --- a/app/Http/Requests/Api/Application/Nests/Eggs/GetEggRequest.php +++ b/app/Http/Requests/Api/Application/Nests/Eggs/GetEggRequest.php @@ -2,6 +2,8 @@ namespace Pterodactyl\Http\Requests\Api\Application\Nests\Eggs; +use Pterodactyl\Models\Egg; +use Pterodactyl\Models\Nest; use Pterodactyl\Services\Acl\Api\AdminAcl; use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest; @@ -24,6 +26,6 @@ class GetEggRequest extends ApplicationApiRequest */ public function resourceExists(): bool { - return $this->getModel('nest')->id === $this->getModel('egg')->nest_id; + return $this->getModel(Nest::class)->id === $this->getModel(Egg::class)->nest_id; } }