This error handling looks familiar, can it be commonized?