How to hide Laravel's 405 Method Not Allowed error screen? - laravel

When directly accessing a URL which use Route::post(), Laravel shows the following 405 Method Not Allowed error screen:
Oops! An Error Occurred
The server returned a "405 Method Not Allowed".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
I think it is not good to give bad people information about the correct method. Am I right?
How to hide 405 Method Not Allowed error screen and show 404 Not Found error instead?
It is better to configure .env or Laravel than to configure nginx or apache.
And I don't want to write 404 error redirect in every controller methods.
I want to hide the error screen only in the production because it is good to know that method is not correct while developing (debug mode is on).

Thanks to #Don'tPanic in the comments of my question, I found the answer.
Laravel offers the option to hide 405 error screen.
You can change 405 error to 404 error and display 404 Not Found error page instead of 405 error page without writing code in every controller action method.
For more detail, see the answer and documentation below:
how to handle 405 error for displaying as webpage laravel
The Render Method
https://laravel.com/docs/5.8/errors#render-method

Related

Laravel dusk asserting for 404 errors

I'm trying to use laravel dusk to test for 404 not found error. Specifically when loading an image. After reading the laravel dusk documentation I've found no asserts that could help me test if a 404 exception occurs.
Is there a good way of getting a browser test to know whether a resource has failed loading or is it simply not possible?
There is intentionally no way to access HTTP status codes:
https://github.com/laravel/dusk/issues/422
https://github.com/facebook/php-webdriver/issues/470
You can use browser -> driver -> manage() -> getLog('browser') to get the log and see if there is a 404 Error

Custom error handling

I am developing a component in joomla 2.5, my component sends a request to some url and gets the response object. If i pass wrong url, joomla takes me to the default page of Error : 500 - No response code found . I want that if user install my component and mistakenly they put wrong url , it should show some custom error message/page which should more meaningful to non-programming person rather than taking user to default error page. Is there some way to add this type of functionality in Joomla without editing template/error.php file in core.
You should have an error.php file in your template, if you don't add one and make it look the way you want. also remember that when you turn debugging off you won't get the stack trace etc.
However error 500 indicates something different than that the url does not exist ("wrong URL"), which would be a 404. 500 is an internal server error and you need to check your logs to figure out what is causing it.

AJAX error, Drupal 7

I got an AJAX error while running Drupal 7.
"An AJAX error occured.
HTTP result code: 500
Debugging information follows:
Path: system/AJAX
StatusText: error
Response text:"
There is no response text. I have looked everywhere and tried a couple of things, but nothing works. Anyone have an idea on how to fix it?
Thanks
Check your watchdog table, if nothing there check the php error log.
Also use Firebug's console to check what is returned after the ajax request for any clues.
Can also try disabling third party modules one at a time to find out what is causing the error.

Opencart Ajax Error unexpected token <

I'm using OpenCart 1.5.1.3 and having this strange error on Guest Shipping in Ajax. I'm getting the error "Unexpected token <".
I have tried everyting, change the Ajax code, look at the controller, but no luck. You can try it yourself at http://www.biancabonte.nl/shop/. Put something in the cart and checkout Direct instead of registering. Then the problem occurs.
Thanks
This is almost certainly due to an error message being output by your store, which precedes the AJAX JSON content. Check your error logs around the time you made/make the request. While they won't contain the < character since they're not formatted like the ones output by PHP, they will still have the actual message. Your error logs will either be in the SYSTEM > ERROR LOGS in the admin, or in your cpanel/plesk/other control panel under logs usually

Redirecting errors in codeigniter

I want all codeigniter errors to be redirected to a custom error page. I have redirected 404 errors with $route['404_override'] = 'errorcontroller'; How can I redirect all the other errors such as db and php
You can always use try and catch block and then redirect to your custom error page. But as per your questions, there are some things you should consider.
Redirect will issue a completely new request which is accomplished with the header sent to the browser. For that reason you will not be able to display the error message unless you save that message in session or something.
Some errors results in PHP throwing exceptions while others don't. Some DB interactions error only raises PHP warnings or error. PHP execution may halt but no exception will be thrown. In such case even wrapping the code in try catch will not be any help. However, you can create a custom error handler and inform PHP to use that handler. Then in the custom error handler you are free to throw exceptions or redirect to error page.
you can also use .htaccess to force redirection to the pages you set at specific header codes [404,304,500] etc
Hope this helps!

Resources