add error management for the getBearerToken fn