diff --git a/CHANGELOG.md b/CHANGELOG.md index 26291d970..c93b6ce10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * File manager rename field would not disappear when pressing the escape key in chrome. [#121](https://github.com/Pterodactyl/Panel/issues/121) * Fixes bug where server image assigned was not being saved to the database. * Fixes instances where selecting auto-deploy would not hide the node selection dropdown. +* Fixes bug in auto-deployment that would throw a `ModelNotFoundException` if the location passed was not valid. Not normally an issue in the panel, but caused display isses for the API. ## v0.5.0-pre.1 (Bodacious Boreopterus) diff --git a/app/Services/DeploymentService.php b/app/Services/DeploymentService.php index ff2f16cbc..5d0c7d5e1 100644 --- a/app/Services/DeploymentService.php +++ b/app/Services/DeploymentService.php @@ -61,9 +61,12 @@ class DeploymentService */ public static function randomNode($location, array $not = []) { - $useLocation = Models\Location::findOrFail($location); - $node = Models\Node::where('location', $useLocation->id)->where('public', 1)->whereNotIn('id', $not)->inRandomOrder()->first(); + $useLocation = Models\Location::where('id', $location)->first(); + if (!$useLocation) { + throw new DisplayException("The location passed was not valid and could not be found."); + } + $node = Models\Node::where('location', $useLocation->id)->where('public', 1)->whereNotIn('id', $not)->inRandomOrder()->first(); if (!$node) { throw new DisplayException("Unable to find a node in location {$useLocation->short} (id: {$useLocation->id}) that is available and has space."); }