cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Go Driver: How to "catch" transaction errors thrown by apoc.util.validate?

benjamin_rood
Node Clone

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.

1 REPLY 1

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
}