Worth refactoring this try/catch logic into a function since it's identical for both?