Sometimes we need to utilise triggers (apoc.trigger.add) to implement a functional constraint in database operation.
The usual way of having this work is to make use of apoc.util.validate, and this raises an exception in Neo4j.
Apart from parsing every single error message from the driver for the exact string matching the exepected error message, is there any way of catching those errors raised by apoc.util.validate, or, as I suspect, is it impossible due to the way it seems the drivers are implemented? I'm using the Go driver.
Edit: I see that in Python and Java driver implementations it is possible to catch specific exception types.
Hello, sorry for the late reply, this fell off my radar.
You can run something like this:
if neo4jErr, ok := err.(*neo4j.Neo4jError); ok {
// example raw error is: Neo.ClientError.General.ForbiddenReadOnlyDatabase
classification := neo4jErr.Classification() // ClientError
category := neo4jErr.Category() // General
title := neo4jErr.Title() // ForbiddenReadOnlyDatabase
// do something with these
}
1 Like
HI Florent, not sure why I never got an email notification about this, but thanks, this is exactly what I was looking for.
Do you know which was the first version of the Go driver that this worked for?
Thanks!
It's been available for a long time, from v1.8 up until today.