yajra / laravel-datatables

jQuery DataTables API for Laravel
https://yajrabox.com/docs/laravel-datatables
MIT License
4.76k stars 859 forks source link

datatables.error = null should respect app.debug & not show exception details to user #1582

Open nie7321 opened 6 years ago

nie7321 commented 6 years ago

Summary of problem or feature request

When the app.debug flag is set to false, SQL errors in the filtering code are causing a popup for the end-user with the exception (in this case, the SQL error).

Per the config/datatables.php file, I can control this behaviour pretty easily:

    /**
     * User friendly message to be displayed on user if error occurs.
     * Possible values:
     * null             - The exception message will be used on error response.
     * 'throw'          - Throws a \Yajra\DataTables\Exceptions\Exception. Use your custom error handler if needed.
     * 'custom message' - Any friendly message to be displayed to the user. You can also use translation key.
     */
    'error'          => env('DATATABLES_ERROR', null),

I would suggest changing the behaviour if the settings is left null: when app.debug = false, default to a custom message instead of exposing the exception to an end-user. This would be more consistent with how the rest of the framework behaves.

I can take a stab at a PR if you concur that this is a good idea.

System details

Laravel 5.5.28, PHP 7.1.8, and Laravel-Datatables 1.0.0

yajra commented 6 years ago

Yes, I agree with you. It's actually on my notes but haven't got the chance to implement it. Can you please do submit a PR. TIA ❤️