예제 #1
0
        public async Task <GetPasswordSaltsResponse> GetPasswordSaltsOverRestEndpoint(string username)
        {
            _ = _logger.Log("FETCH PASSWORD SALTS");
            HttpResponseMessage response;

            try
            {
                response = await _api.GetPasswordSalts(username);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("timeout"))
                {
                    throw new Timeout();
                }
                throw;
            }

            if (response.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <GetPasswordSaltsResponse>(
                           await response.Content.ReadAsStringAsync()));
            }

            var one = ParseGenericErrors(await response.Content.ReadAsStringAsync(), response.StatusCode);

            if (one != null)
            {
                throw one;
            }

            var two = await ParseGenericUsernamePasswordError(response);

            if (two != null)
            {
                throw two;
            }

            if (await response.Content.ReadAsStringAsync() == "User not found")
            {
                throw new UsernameOrPasswordMismatch();
            }

            throw new Exception($"Unknown error when fetching password salts: {response.StatusCode}");
        }