Move error message mapping into if