For example, for a normal request, the return method is as follows: {code ...} it is inconvenient for the api to return html. How to make any errors return json, including code errors, database connection errors such as a normal request? The Return method is as follows:
Return response ($ result, $ code); // return json
It is inconvenient to see how to make any errors return json, including code errors and database connection errors.
Reply content:
For example, for a normal request, the return method is as follows:
Return response ($ result, $ code); // return json
It is inconvenient to see how to make any errors return json, including code errors and database connection errors.
App \ Exceptions \ Handler
Directly return response ()-> json ();
You can return different json values for different errors.
Here
Try {$ conn = new redis ();} catch (\ Exception $ e) {var_dump ($ e); // capture error}