DotNet4Neo4j / Neo4jClient

.NET client binding for Neo4j
https://www.nuget.org/packages/Neo4jClient
Microsoft Public License
431 stars 146 forks source link

Library does not return error details, just 500 #343

Closed andreycha closed 4 years ago

andreycha commented 4 years ago

Hi,

I've ran into the following issue: when I execute query that fails for some reason (DB constraint in my case), library does not return error details:

System.Exception: Received an unexpected HTTP status when executing the request.

The response status was: 500 Server Error

The response from Neo4j (which might include useful detail!) was: 
   at Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteGetCypherResults[TResult](CypherQuery query)
   _here goes my application stacktrace_

I use http connection string, and when I execute same query against /db/data/cypher, endpoint actually returns 400 Bad Request with error details (same as in Neo4j logs):

{
    "message": "Node(5714) with label `Person` must have the property `Name`",
    "exception": "ConstraintViolationException",
    "fullname": "org.neo4j.graphdb.ConstraintViolationException",
    "stackTrace": [
        ...
    ],
    "cause": {
        "exception": "ConstraintViolationTransactionFailureException",
        "cause": {
            "exception": "NodePropertyExistenceException",
            "fullname": "org.neo4j.kernel.api.exceptions.schema.NodePropertyExistenceException",
            "stackTrace": [
                ...
            ],
            "message": "Node(5714) does not satisfy CONSTRAINT ON ( label[8]:label[8] ) ASSERT exists(label[8].property[1]).",
            "errors": [
                {
                    "code": "Neo.ClientError.Schema.ConstraintValidationFailed",
                    "message": "Node(5714) does not satisfy CONSTRAINT ON ( label[8]:label[8] ) ASSERT exists(label[8].property[1])."
                }
            ]
        },
        "fullname": "org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException",
        "stackTrace": [
            ...
        ],
        "message": "Node(5714) with label `Person` must have the property `Name`",
        "errors": [
            {
                "code": "Neo.ClientError.Schema.ConstraintValidationFailed",
                "message": "Node(5714) with label `Person` must have the property `Name`"
            }
        ]
    },
    "errors": [
        {
            "code": "Neo.ClientError.Schema.ConstraintValidationFailed",
            "message": "Node(5714) with label `Person` must have the property `Name`"
        }
    ]
}

Neo4j version: 3.5.12 Enterprise Neo4jClient version: 3.1.0.6

Could you please advise?

UPDATE

Looks like the issue might be in this line: https://github.com/Readify/Neo4jClient/blob/3d58def38afd3b4a029f97a4cae247ef2755a5ba/Neo4jClient.Shared/Execution/HttpResponseMessageExtensions.cs#L51

Library expects content type to be "application/json", and if it's not provided, treats response as 500. Neo4j /db/data/cypher responds with "application/json;charset=utf-8".

It's only not clear why raw response is empty: https://github.com/Readify/Neo4jClient/blob/3d58def38afd3b4a029f97a4cae247ef2755a5ba/Neo4jClient.Shared/Execution/HttpResponseMessageExtensions.cs#L38

cskardon commented 4 years ago

Can you use the BoltGraphClient?

andreycha commented 4 years ago

Yes, that's what I wanted to try next. Will it help?

cskardon commented 4 years ago

It should give you the proper error message - and it should only be one line to change

andreycha commented 4 years ago

It will take me some time. Once I switched to bolt, some queries started to fail at deserialization stage. Will get back to you once I'm done with it.