Skip to content

Commit f9878d8

Browse files
committed
Fix error handling for large files (and endpoints called as non-json)
1 parent 7f2b477 commit f9878d8

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Exceptions\Http\Server;
114

125
use Pterodactyl\Exceptions\DisplayException;
136

147
class FileSizeTooLargeException extends DisplayException
158
{
9+
/**
10+
* FileSizeTooLargeException constructor.
11+
*/
12+
public function __construct()
13+
{
14+
parent::__construct('The file you are attempting to open is too large to view in the file editor.');
15+
}
1616
}

app/Repositories/Wings/DaemonFileRepository.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ public function getContent(string $path, int $notLargerThan = null): string
4949
$length = (int) $response->getHeader('Content-Length')[0] ?? 0;
5050

5151
if ($notLargerThan && $length > $notLargerThan) {
52-
throw new FileSizeTooLargeException(
53-
trans('server.files.exceptions.max_size')
54-
);
52+
throw new FileSizeTooLargeException;
5553
}
5654

5755
return $response->getBody()->__toString();

config/pterodactyl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
| This array includes the MIME filetypes that can be edited via the web.
173173
*/
174174
'files' => [
175-
'max_edit_size' => env('PTERODACTYL_FILES_MAX_EDIT_SIZE', 50000),
175+
'max_edit_size' => env('PTERODACTYL_FILES_MAX_EDIT_SIZE', 1024 * 512),
176176
'editable' => [
177177
'application/json',
178178
'application/javascript',

resources/scripts/api/http.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ export default http;
2929
*/
3030
export function httpErrorToHuman (error: any): string {
3131
if (error.response && error.response.data) {
32-
const { data } = error.response;
32+
let { data } = error.response;
33+
34+
// Some non-JSON requests can still return the error as a JSON block. In those cases, attempt
35+
// to parse it into JSON so we can display an actual error.
36+
if (typeof data === 'string') {
37+
try {
38+
data = JSON.parse(data);
39+
} catch (e) {
40+
// do nothing, bad json
41+
}
42+
}
43+
3344
if (data.errors && data.errors[0] && data.errors[0].detail) {
3445
return data.errors[0].detail;
3546
}

0 commit comments

Comments
 (0)