move error logging out of the api machinery