Пример #1
0
 /**
  * {@inheritdoc}
  */
 public static function create(HttpRequestInterface $request, HttpResponseInterface $response = null, Exception $previous = null, array $handlerContext = null)
 {
     if ($request instanceof RequestInterface && $response instanceof ResponseInterface) {
         static $clientErrorCodes = [-32600, -32601, -32602, -32700];
         $errorCode = $response->getRpcErrorCode();
         if (in_array($errorCode, $clientErrorCodes)) {
             $label = 'Client RPC error response';
             $className = __NAMESPACE__ . '\\ClientException';
         } else {
             $label = 'Server RPC error response';
             $className = __NAMESPACE__ . '\\ServerException';
         }
         $message = $label . ' [uri] ' . $request->getRequestTarget() . ' [method] ' . $request->getRpcMethod() . ' [error code] ' . $errorCode . ' [error message] ' . $response->getRpcErrorMessage();
         return new $className($message, $request, $response, $previous);
     }
     return parent::create($request, $response, $previous);
 }