Skip to content

Commit 620c624

Browse files
committed
Fix exception thrown when accessing /nests/:id/eggs/:id API endpoint
1 parent e7e50bc commit 620c624

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa
33

44
This project follows [Semantic Versioning](http://semver.org) guidelines.
55

6+
## v0.7.2 (Derelict Dermodactylus)
7+
### Fixed
8+
* Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint.
9+
610
## v0.7.1 (Derelict Dermodactylus)
711
### Fixed
812
* Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted.

app/Http/Requests/Api/Application/ApplicationApiRequest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Pterodactyl\Exceptions\PterodactylException;
1010
use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings;
1111
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12+
use Symfony\Component\Routing\Exception\InvalidParameterException;
1213

1314
abstract class ApplicationApiRequest extends FormRequest
1415
{
@@ -76,22 +77,23 @@ public function key(): ApiKey
7677
}
7778

7879
/**
79-
* Grab a model from the route parameters. If no model exists under
80-
* the specified key a default response is returned.
80+
* Grab a model from the route parameters. If no model is found in the
81+
* binding mappings an exception will be thrown.
8182
*
8283
* @param string $model
83-
* @param mixed $default
8484
* @return mixed
85+
*
86+
* @throws \Symfony\Component\Routing\Exception\InvalidParameterException
8587
*/
86-
public function getModel(string $model, $default = null)
88+
public function getModel(string $model)
8789
{
8890
$parameterKey = array_get(array_flip(ApiSubstituteBindings::getMappings()), $model);
8991

90-
if (! is_null($parameterKey)) {
91-
$model = $this->route()->parameter($parameterKey);
92+
if (is_null($parameterKey)) {
93+
throw new InvalidParameterException;
9294
}
9395

94-
return $model ?? $default;
96+
return $this->route()->parameter($parameterKey);
9597
}
9698

9799
/*

app/Http/Requests/Api/Application/Nests/Eggs/GetEggRequest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Pterodactyl\Http\Requests\Api\Application\Nests\Eggs;
44

5+
use Pterodactyl\Models\Egg;
6+
use Pterodactyl\Models\Nest;
57
use Pterodactyl\Services\Acl\Api\AdminAcl;
68
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
79

@@ -24,6 +26,6 @@ class GetEggRequest extends ApplicationApiRequest
2426
*/
2527
public function resourceExists(): bool
2628
{
27-
return $this->getModel('nest')->id === $this->getModel('egg')->nest_id;
29+
return $this->getModel(Nest::class)->id === $this->getModel(Egg::class)->nest_id;
2830
}
2931
}

0 commit comments

Comments
 (0)