I'm building a web-application with Laravel with a file uploader in ajax.
I would like handle in PHP when the file exceeds the UPLOAD_MAX_SIZE
limit.
Currently, I am adding this to /app/exception/Handler.php
public function render($request, Throwable $e): Response {
if ($e instanceof PostTooLargeException) {
return response()->json([
'error' => 'Il file supera le dimensioni massime consentite. ' . ini_get("upload_max_filesize"),
], 422);
}
return parent::render($request, $e);
}
The response that I receive add two extra rows:
<br />
<b>Warning</b>: POST Content-Length of 10087828 bytes exceeds the limit of 8388608 bytes in <b>Unknown</b> on line <b>0</b><br />
{"error":"Il file supera le dimensioni massime consentite. 2M"}
I tried with APP_DEBUG
set to false
, and error_reporting(0)
without success.
How can return only the json?