API Error display

Posted 5 months ago by megaman7

I understand how error handling is supposed to occur for regular http calls.

Laravel has custom ways to handle specific error types and you can extend this by adding conditional logic to the App\Exceptions\Handler class which can detect errors based on anything you like (i have used error class type, route name and error message) In addition you can set a 404.blade.php file which will be used whenever there is a 404 status code (unless your conditional logic previously mentioned returns before laravel gets this far)

What is the best way to handle errors which are generated by an API?

currently i have conditional logic which detects any error other than a NotFoundHttpException (so i do not override the 404 behavior) and return a custom view. The API does return an error message but i do not display this on the custom error page because it may contain info i dont want a user to see.

Is my current way an acceptable way or can laravel handle this in some other way.

Please sign in or create an account to participate in this conversation.