自定义错误处理程序
2023年5月11日小于 1 分钟
自定义错误处理程序
本主题介绍如何创建自己的错误处理程序逻辑。
可以提供自己的自定义错误处理程序逻辑,以在整个生产环境中实现标准化。
引用未知灰度标帜(Feature Flag)键时,将调用此错误处理程序。
请参阅下面的代码示例。如果未重写错误处理程序,则默认使用无操作错误处理程序。
.PHP
use Eyeofcloud\ErrorHandler\DefaultErrorHandler;  
$eyeofcloudClient = new Eyeofcloud($datafile, null, null, new DefaultErrorHandler());要在生产环境中对 SDK 配置进行更精细的控制,还可以为 Eyeofcloud 客户端传入自定义错误处理程序。自定义错误处理程序可以让你更好地控制如何处理来自云眼灰度实验 SDK 的任何错误。
.PHP
use Eyeofcloud\ErrorHandler\ErrorHandlerInterface;  
/**  
* Class MyCustomErrorHandler  
*    
* Custom error handler class that extends and overrides the   
* handleError method allowing you to define custom behavior.  
*  
*/ 
class MyCustomErrorHandler implements ErrorHandlerInterface {     
    public function handleError(Exception $error)     {        
        // You can put custom logic here about how you want to handle the error.        
        // For example here we simply throw the error.               
        throw $error;     
    } 
}  
// This error handler can then be used when initializing the Eyeofcloud SDK.  
$eyeofcloudClient = new Eyeofcloud($datafile, null, null, new MyCustomErrorHandler());
··`