File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 88use Illuminate \Http \Response ;
99use Illuminate \Container \Container ;
1010use Prologue \Alerts \AlertsMessageBag ;
11+ use Symfony \Component \HttpKernel \Exception \HttpExceptionInterface ;
1112
12- class DisplayException extends PterodactylException
13+ class DisplayException extends PterodactylException implements HttpExceptionInterface
1314{
1415 public const LEVEL_DEBUG = 'debug ' ;
1516 public const LEVEL_INFO = 'info ' ;
@@ -51,17 +52,29 @@ public function getStatusCode()
5152 return Response::HTTP_BAD_REQUEST ;
5253 }
5354
55+ /**
56+ * @return array
57+ */
58+ public function getHeaders ()
59+ {
60+ return [];
61+ }
62+
5463 /**
5564 * Render the exception to the user by adding a flashed message to the session
5665 * and then redirecting them back to the page that they came from. If the
5766 * request originated from an API hit, return the error in JSONAPI spec format.
5867 *
5968 * @param \Illuminate\Http\Request $request
6069 *
61- * @return \Illuminate\Http\RedirectResponse
70+ * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\ RedirectResponse
6271 */
6372 public function render ($ request )
6473 {
74+ if ($ request ->expectsJson ()) {
75+ return response ()->json (Handler::toArray ($ this ), $ this ->getStatusCode (), $ this ->getHeaders ());
76+ }
77+
6578 app (AlertsMessageBag::class)->danger ($ this ->getMessage ())->flash ();
6679
6780 return redirect ()->back ()->withInput ();
Original file line number Diff line number Diff line change @@ -284,4 +284,13 @@ protected function extractPrevious(Throwable $e): array
284284
285285 return $ previous ;
286286 }
287+
288+ /**
289+ * Helper method to allow reaching into the handler to convert an exception
290+ * into the expected array response type.
291+ */
292+ public static function toArray (Throwable $ e ): array
293+ {
294+ return (new self (app ()))->convertExceptionToArray ($ e );
295+ }
287296}
You can’t perform that action at this time.
0 commit comments