Simplify error handling, add error codes

This work simplifies and improves the custom error type(s). It partially reverts an earlier contribution. 

Primary change is moving to an Error type with fields corresponding to the underlying pq error fields.