Skip to content

Commit 0ccaa16

Browse files
committed
Fix exceptions thrown to mimic proper HTTP status codes
1 parent 69c2e89 commit 0ccaa16

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

app/Http/Controllers/API/UserController.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Http\Request;
66

7-
use Dingo\Api\Exception\StoreResourceFailedException;
7+
use Dingo\Api\Exception\ResourceException;
88

99
use Pterodactyl\Models;
1010
use Pterodactyl\Transformers\UserTransformer;
@@ -14,6 +14,7 @@
1414
use Pterodactyl\Exceptions\DisplayException;
1515
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1616
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
17+
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
1718

1819
/**
1920
* @Resource("Users")
@@ -109,11 +110,11 @@ public function postUser(Request $request)
109110
'id' => $create
110111
]));
111112
} catch (DisplayValidationException $ex) {
112-
throw new StoreResourceFailedException('A validation error occured.', json_decode($ex->getMessage(), true));
113+
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
113114
} catch (DisplayException $ex) {
114-
throw new StoreResourceFailedException($ex->getMessage());
115+
throw new ResourceException($ex->getMessage());
115116
} catch (\Exception $ex) {
116-
throw new StoreResourceFailedException('Unable to create a user on the system due to an error.');
117+
throw new ServiceUnavailableHttpException('Unable to create a user on the system due to an error.');
117118
}
118119
}
119120

@@ -142,11 +143,11 @@ public function patchUser(Request $request, $id)
142143
$user->update($id, $request->all());
143144
return Models\User::findOrFail($id);
144145
} catch (DisplayValidationException $ex) {
145-
throw new StoreResourceFailedException('A validation error occured.', json_decode($ex->getMessage(), true));
146+
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
146147
} catch (DisplayException $ex) {
147-
throw new StoreResourceFailedException($ex->getMessage());
148+
throw new ResourceException($ex->getMessage());
148149
} catch (\Exception $ex) {
149-
throw new StoreResourceFailedException('Unable to create a user on the system due to an error.');
150+
throw new ServiceUnavailableHttpException('Unable to update a user on the system due to an error.');
150151
}
151152
}
152153

@@ -171,9 +172,9 @@ public function deleteUser(Request $request, $id)
171172
$user->delete($id);
172173
return $this->response->noContent();
173174
} catch (DisplayException $ex) {
174-
throw new StoreResourceFailedException($ex->getMessage());
175+
throw new ResourceException($ex->getMessage());
175176
} catch (\Exception $ex) {
176-
throw new StoreResourceFailedException('Unable to delete this user due to an error.');
177+
throw new ServiceUnavailableHttpException('Unable to delete this user due to an error.');
177178
}
178179
}
179180

0 commit comments

Comments
 (0)