WIP: Trap postgres errors in middleware

Fixes #39