Skip to content

Error Handling

Piotr Kowalczuk edited this page Sep 7, 2018 · 3 revisions

In general pqt do not produce any custom errors. Errors that any method function returns comes from its dependencies. List of dependencies will differ based on what was chosen to be generated. The most important ones are:

Constraints

Each constraint within the schema will be represented by a constant in go codebase. If the returned error is of type [pq.Errors](github.com/lib/pq.Errors and it carries Constraint value. It is possible to handle it, as in the example below.

if err != nil {
	switch pqt.ErrorConstraint(err) {
		case Table<Entity>Constraint<SomeForeignKey>:
			log.Fatal("entity with such id does not exists")
		default:
			//...
	}
}
Clone this wiki locally