Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

3Descape's avatar

Custom 413 PostTooLarge Exeption Handling

Hellor everybody!

When posting a too large file on my Xampp testserver I get an expected PostTooLargeException. I use custom exeption handling, so the error is formatted in json and I can display a custom message in german, that I then output in my vue component.

Handler.php in render function:

if ($exception instanceof PostTooLargeException) {
    $message = ['errors' => ['file' => ['Datei ist zu groß.']]];
    return response()->json($message, 413);
}

Now my problem: The response not only contains my json error object, but also a message I can't get rid of:

Warning: POST Content-Length of 48764135 bytes exceeds the limit of 10485760 bytes in Unknown on line 0
{"errors":{"file":["Datei ist zu gro\u00df."]}}

Where the "Warning: POST Content-Length..." is the unwanted part of the response.

Maybe someone knows whether Laravel puts this in the response or if I have to disable this somewhere in my Xampp config files. Anyway, any help is much appreciated!

0 likes
7 replies
bobbybouwmann's avatar

It looks like you're posting a body that is way too big for the request! Maybe you should just fix the warning?

To fix this most of the time you either need to update the post_max_size and the upload_max_filesize for your application. You can Google on how to do that ;)

Note that this is just a warning from your system! Your application might nog be able to proces the post request because of the size!

3Descape's avatar

First of all thank you for answering. I'm fine with the exeption and I don't want to increase post_max_size or uploud_max_filesize. Even if I do so, I still need to handle the error, because I can't allow the user to uploud a file of any size.

The result I would like to get is that only my custom json object is included in the response, so I can handle the error on the client side with vue. Maybe someone has an idea what part of the laravel application or xampp is rendering the first error part and whether it is possible to disable it or not. Thx in advance!

Cronix's avatar

Even if I do so, I still need to handle the error, because I can't allow the user to uploud a file of any size.

Use a validation rule (max) for that to tell the max allowed filesize of the upload.

3Descape's avatar

Thank you very much for this tip, I am going to use this as a fallback solution! Still I would like to use the custom exeption handling as I have several file uplouds in my application and this would be a way to handle it globally and not per controller/fileuploud. Also it worked in the past, so there has to be a solution to this problem..

Cronix's avatar
Cronix
Best Answer
Level 67

Do you have display_errors or display_startup_errors turned on in php.ini? I believe that's why you're seeing the error in addition to your custom error.

1 like
3Descape's avatar

Thank you very, very much, this fixed it for me! Toyed around with these already, but seems like I did something wrong. Thank you very much again!

Cronix's avatar

You're welcome! I'm glad it's working for you now.

Please or to participate in this conversation.