Fix error handling

The error handling seemed broken. All errors logged with log_to_postgres() were logged as NOTICE.