简体   繁体   English

neo4j-php-client中的错误处理程序

[英]Error handlers in neo4j-php-client

I downloaded and installed neo4j-php-client and neo4j 2.3.2. 我下载并安装了neo4j-php-client和neo4j 2.3.2。 Actually all works fine, but I just wondering why there is no error handlers in this php client? 其实一切正常,但我只是想知道为什么在此php客户端中没有错误处理程序? For example if there is an error in cypher query, no error has throwing to be easy to catch it. 例如,如果密码查询中存在错误,则没有错误可以轻松捕获。 I searching through the network, but I can't found a solution. 我通过网络搜索,但是找不到解决方案。

Do anybody have an idea how to turn on error handlers? 有人知道如何打开错误处理程序吗?

Thanks in advance. 提前致谢。

I'm the maintainer of neo4j-php-client . 我是neo4j-php-clientneo4j-php-client

When you send a query to Neo4j, it is actually sent via Guzzle. 当您向Neo4j发送查询时,它实际上是通过Guzzle发送的。

Of course there is a try/catch block for handling exceptions, which is located here : 当然,这里有一个try / catch块用于处理异常,它位于:

https://github.com/graphaware/neo4j-php-client/blob/master/src/HttpClient/GuzzleHttpClient.php#L76 https://github.com/graphaware/neo4j-php-client/blob/master/src/HttpClient/GuzzleHttpClient.php#L76

If there is an error in your cypher query, an exception will be thrown of course, the exception is of type Neo4jException ( https://github.com/graphaware/neo4j-php-client/blob/master/src/Exception/Neo4jException.php ) 如果密码查询中存在错误,则当然会引发一个异常,该异常的类型为Neo4jExceptionhttps://github.com/graphaware/neo4j-php-client/blob/master/src/Exception/Neo4jException .php

Here is a simple code with a cypher syntax error and you can see an exception is thrown : 这是带有密码语法错误的简单代码,您可以看到抛出了异常:

<?php

require_once __DIR__ .'/vendor/autoload.php';

use Neoxygen\NeoClient\ClientBuilder;

$client = ClientBuilder::create()
    ->addConnection('default', 'http', 'localhost', 7474)
    ->setAutoFormatResponse(true)
    ->build();

$query = 'MATCH (n) RETURN x';

$result = $client->sendCypherQuery($query)->getResult();

- --

ikwattro@graphaware ~/d/g/p/neo4j-php-client> php test.php
PHP Fatal error:  Uncaught Neoxygen\NeoClient\Exception\Neo4jException: Neo4j Exception with code "Neo.ClientError.Statement.InvalidSyntax" and message "Variable `x` not defined (line 1, column 18 (offset: 17))
"MATCH (n) RETURN x"
                  ^" in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php:117
Stack trace:
#0 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php(104): Neoxygen\NeoClient\Extension\AbstractExtension->checkResponseErrors(Array)
#1 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/NeoClientCoreExtension.php(98): Neoxygen\NeoClient\Extension\AbstractExtension->handleHttpResponse(Object(Neoxygen\NeoClient\Request\Response))
#2 [internal function]: Neoxygen\NeoClient\Extension\NeoClientCoreExtension->sendCypherQuery('MATCH (n) RETUR...')
#3 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/ExtensionManager.php(53): call_user_func_array(Array, Array)
#4 /Users/ikwattro/dev/graphaware/php/neo4j-php-cli in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php on line 117

Fatal error: Uncaught Neoxygen\NeoClient\Exception\Neo4jException: Neo4j Exception with code "Neo.ClientError.Statement.InvalidSyntax" and message "Variable `x` not defined (line 1, column 18 (offset: 17))
"MATCH (n) RETURN x"
                  ^" in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php:117
Stack trace:
#0 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php(104): Neoxygen\NeoClient\Extension\AbstractExtension->checkResponseErrors(Array)
#1 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/NeoClientCoreExtension.php(98): Neoxygen\NeoClient\Extension\AbstractExtension->handleHttpResponse(Object(Neoxygen\NeoClient\Request\Response))
#2 [internal function]: Neoxygen\NeoClient\Extension\NeoClientCoreExtension->sendCypherQuery('MATCH (n) RETUR...')
#3 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/ExtensionManager.php(53): call_user_func_array(Array, Array)
#4 /Users/ikwattro/dev/graphaware/php/neo4j-php-cli in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php on line 117

Thanks for the answer. 感谢您的回答。 The problem is seems on my end, I figured out after few tests - Error hanldering overwrites by the php framework. 问题似乎是对我而言,我经过几次测试就发现了-错误php框架覆盖了错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM