Laravel Custom Exception Handler Based on Route Group

public function render($request, Exception $e)
{
   
if($request->is(‘api/*’)){
       
return response()->json([
           
‘error_message’ => $e->getMessage(),

           
‘status’ => Response::HTTP_BAD_REQUEST
        ]);
    }

    return parent::render($request, $e);

}