public async Task <UserApiResponse> GetUser(string userId) { var response = new UserApiResponse(); try { var user = await identityApi.GetUser(userId); response.Success = true; response.Data = user; } catch (ValidationApiException validationException) { // handle validation here by using validationException.Content, // which is type of ProblemDetails according to RFC 7807 response.Message = validationException.Content.Detail; // If the response contains additional properties on the problem details, // they will be added to the validationException.Content.Extensions collection. } catch (ApiException exception) { // other exception handling response.Message = exception.Content; } catch (Exception exception) { response.Message = exception.Message; } return(response); }
private async Task FetchUsers() { try { await Task.Delay(2000); this.Client.BaseAddress = new Uri("https://randomuser.me"); var jsonStream = await this.Client.GetStreamAsync("/api?results=10"); userApiResponse = await JsonSerializer.DeserializeAsync <UserApiResponse>(jsonStream); } catch (Exception a) { Util.Log(a); // throw; } }
public async Task <string> GetUserId() { ChatServiceConfig.ChatConfig.ClientConfig provider = context.Service.ConfigReader .GetCheckedValue <List <ChatServiceConfig.ChatConfig.ClientConfig>, ChatServiceConfig>() .First(x => x.provider == ClientName); string clientID = provider.client_id; string url = NewApiUrl + "/users?login="******"client-id", clientID); HttpResponseMessage response = await httpClient.GetAsync(url); string JsonString = await response.Content.ReadAsStringAsync(); UserApiResponse userResponse = JsonConvert.DeserializeObject <UserApiResponse>(JsonString); string UserID = userResponse.data[0].id; httpClient.DefaultRequestHeaders.Remove("client-id"); return(UserID); }