TP5 custom global exception handling, all exceptions thrown are passed automatically Define the render method to render and then return to the client for display.
You need to customize the render method of the handle and overwrite it:
namespace app\lib\exception; use think\Exception; use think\exception\Handle; class ExceptionHandler extends Handle { public function render(Exception $e) { //TODO: return json('invalid request') } }
After that, the postman verification interface appears and the following error message is incompatible:
Trace the original Handle. php file,
Check use and find that the source file uses Exception
, and I use think\Exception
:
Modify the code:
namespace app\lib\exception; use Exception; use think\exception\Handle; class ExceptionHandler extends Handle { public function render(Exception $e) { //TODO: return json('invalid request') } }
The result is correct: