Replace the if case with when

We're returning nil in the failure case so we can remove this extra
line.