diff --git a/app/Exceptions/Http/Server/FileSizeTooLargeException.php b/app/Exceptions/Http/Server/FileSizeTooLargeException.php index c12cb7b2..59a53d3d 100644 --- a/app/Exceptions/Http/Server/FileSizeTooLargeException.php +++ b/app/Exceptions/Http/Server/FileSizeTooLargeException.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Exceptions\Http\Server; @@ -13,4 +6,11 @@ use Pterodactyl\Exceptions\DisplayException; class FileSizeTooLargeException extends DisplayException { + /** + * FileSizeTooLargeException constructor. + */ + public function __construct() + { + parent::__construct('The file you are attempting to open is too large to view in the file editor.'); + } } diff --git a/app/Repositories/Wings/DaemonFileRepository.php b/app/Repositories/Wings/DaemonFileRepository.php index 23c1a23a..e506f1d0 100644 --- a/app/Repositories/Wings/DaemonFileRepository.php +++ b/app/Repositories/Wings/DaemonFileRepository.php @@ -49,9 +49,7 @@ class DaemonFileRepository extends DaemonRepository $length = (int) $response->getHeader('Content-Length')[0] ?? 0; if ($notLargerThan && $length > $notLargerThan) { - throw new FileSizeTooLargeException( - trans('server.files.exceptions.max_size') - ); + throw new FileSizeTooLargeException; } return $response->getBody()->__toString(); diff --git a/config/pterodactyl.php b/config/pterodactyl.php index 4379c753..fe4f2372 100644 --- a/config/pterodactyl.php +++ b/config/pterodactyl.php @@ -172,7 +172,7 @@ return [ | This array includes the MIME filetypes that can be edited via the web. */ 'files' => [ - 'max_edit_size' => env('PTERODACTYL_FILES_MAX_EDIT_SIZE', 50000), + 'max_edit_size' => env('PTERODACTYL_FILES_MAX_EDIT_SIZE', 1024 * 512), 'editable' => [ 'application/json', 'application/javascript', diff --git a/resources/scripts/api/http.ts b/resources/scripts/api/http.ts index d4cf1133..14b27cdb 100644 --- a/resources/scripts/api/http.ts +++ b/resources/scripts/api/http.ts @@ -29,7 +29,18 @@ export default http; */ export function httpErrorToHuman (error: any): string { if (error.response && error.response.data) { - const { data } = error.response; + let { data } = error.response; + + // Some non-JSON requests can still return the error as a JSON block. In those cases, attempt + // to parse it into JSON so we can display an actual error. + if (typeof data === 'string') { + try { + data = JSON.parse(data); + } catch (e) { + // do nothing, bad json + } + } + if (data.errors && data.errors[0] && data.errors[0].detail) { return data.errors[0].detail; }