Fix error cases in qr code scanning