JayJay123
JayJay123

Reputation: 77

How do I customize laravel fatal error exception?

I wanted to know how do I customize laravel Fatal Error message? I don't like the default one that looks like this

FatalErrorException

Upvotes: 0

Views: 1337

Answers (3)

Yasir Nazar
Yasir Nazar

Reputation: 61

In your .env file, updating APP_ENV=production will not render the above error trace.

Some exceptions describe HTTP error codes from the server. For example, this may be a "page not found" error (404), an "unauthorized error" (401) or even a developer generated 500 error.

Laravel makes it easy to display custom error pages for various HTTP status codes. For example, if you wish to customize the error page for 404 HTTP status codes, create a resources/views/errors/404.blade.php. This file will be served on all 404 errors generated by your application. The views within this directory should be named to match the HTTP status code they correspond to.

Upvotes: 1

Peter Matisko
Peter Matisko

Reputation: 2253

I would suggest using try{} catch(){} block which allows you to detect the type of the error and act accrodingly. In my project, I use my own Exception class that has a standard form. It can be sent to API or view.

Upvotes: 0

Flame
Flame

Reputation: 7561

The error message you're viewing is only visible in the local environment. This view is generated by package filp/whoops as seen in composer.json. When you switch your .env file to production (APP_ENV=production), this is no longer seen and instead shows a stripped down error page that doesnt give away these debugging details.

If you want to change this for local environment, take a look at your Exceptions Handler's render method and you should be able to customize it.

Upvotes: 4

Related Questions