88use Pterodactyl \Models \AuditLog ;
99use Illuminate \Http \JsonResponse ;
1010use Pterodactyl \Models \Permission ;
11- use Illuminate \Validation \ UnauthorizedException ;
11+ use Illuminate \Auth \ Access \ AuthorizationException ;
1212use Pterodactyl \Services \Backups \DeleteBackupService ;
1313use Pterodactyl \Services \Backups \DownloadLinkService ;
1414use Pterodactyl \Services \Backups \InitiateBackupService ;
@@ -63,11 +63,12 @@ public function __construct(
6363 *
6464 * @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
6565 * @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
66+ * @throws \Illuminate\Auth\Access\AuthorizationException
6667 */
6768 public function index (Request $ request , Server $ server ): array
6869 {
6970 if (!$ request ->user ()->can (Permission::ACTION_BACKUP_READ , $ server )) {
70- throw new UnauthorizedException ();
71+ throw new AuthorizationException ();
7172 }
7273
7374 $ limit = min ($ request ->query ('per_page ' ) ?? 20 , 50 );
@@ -109,11 +110,12 @@ public function store(StoreBackupRequest $request, Server $server): array
109110 *
110111 * @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
111112 * @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
113+ * @throws \Illuminate\Auth\Access\AuthorizationException
112114 */
113115 public function view (Request $ request , Server $ server , Backup $ backup ): array
114116 {
115117 if (!$ request ->user ()->can (Permission::ACTION_BACKUP_READ , $ server )) {
116- throw new UnauthorizedException ();
118+ throw new AuthorizationException ();
117119 }
118120
119121 return $ this ->fractal ->item ($ backup )
@@ -130,7 +132,7 @@ public function view(Request $request, Server $server, Backup $backup): array
130132 public function delete (Request $ request , Server $ server , Backup $ backup ): JsonResponse
131133 {
132134 if (!$ request ->user ()->can (Permission::ACTION_BACKUP_DELETE , $ server )) {
133- throw new UnauthorizedException ();
135+ throw new AuthorizationException ();
134136 }
135137
136138 $ server ->audit (AuditLog::SERVER__BACKUP_DELETED , function (AuditLog $ audit ) use ($ backup ) {
@@ -146,11 +148,13 @@ public function delete(Request $request, Server $server, Backup $backup): JsonRe
146148 * Download the backup for a given server instance. For daemon local files, the file
147149 * will be streamed back through the Panel. For AWS S3 files, a signed URL will be generated
148150 * which the user is redirected to.
151+ *
152+ * @throws \Illuminate\Auth\Access\AuthorizationException
149153 */
150154 public function download (Request $ request , Server $ server , Backup $ backup ): JsonResponse
151155 {
152156 if (!$ request ->user ()->can (Permission::ACTION_BACKUP_DOWNLOAD , $ server )) {
153- throw new UnauthorizedException ();
157+ throw new AuthorizationException ();
154158 }
155159
156160 switch ($ backup ->disk ) {
@@ -179,7 +183,7 @@ public function download(Request $request, Server $server, Backup $backup): Json
179183 public function restore (Request $ request , Server $ server , Backup $ backup ): JsonResponse
180184 {
181185 if (!$ request ->user ()->can (Permission::ACTION_BACKUP_RESTORE , $ server )) {
182- throw new UnauthorizedException ();
186+ throw new AuthorizationException ();
183187 }
184188
185189 // Cannot restore a backup unless a server is fully installed and not currently
0 commit comments