Ejemplo n.º 1
0
        public async Task <ApiResponseResult <AuthInfo> > GetAuthInfoResponse(AuthInfoRequestData data)
        {
            HttpRequestMessage request = GetRequest(HttpMethod.Post, "auth/info");

            try
            {
                request.Content = GetJsonContent(data);

                using (HttpResponseMessage response = await _client.SendAsync(request).ConfigureAwait(false))
                {
                    string body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    ApiResponseResult <AuthInfo> validatedResponse = ApiResponseResult <AuthInfo>(body, response.StatusCode);
                    if (validatedResponse.Success && string.IsNullOrEmpty(validatedResponse.Value.Salt))
                    {
                        return(Logged(Api.ApiResponseResult <AuthInfo> .Fail(response.StatusCode,
                                                                             "Incorrect login credentials. Please try again")));
                    }
                    return(Logged(validatedResponse));
                }
            }
            catch (Exception e) when(e.IsApiCommunicationException())
            {
                throw new HttpRequestException(e.Message, e);
            }
        }
Ejemplo n.º 2
0
 private void HandleResult <T>(ApiResponseResult <T> result)
     where T : BaseResponse
 {
     if (result.Failure && !result.Actions.IsNullOrEmpty())
     {
         HandleActionableFailureResult(result);
     }
 }
Ejemplo n.º 3
0
        protected ApiResponseResult <T> Logged <T>(ApiResponseResult <T> result, string message = null) where T : BaseResponse
        {
            if (result.Failure)
            {
                _logger.Error($"API: {(!string.IsNullOrEmpty(message) ? message : "Request")} failed: {result.Error}");
            }

            return(result);
        }
Ejemplo n.º 4
0
        private void HandleActionableFailureResult <T>(ApiResponseResult <T> result)
            where T : BaseResponse
        {
            ApiResponseResult <BaseResponse> baseResponseResult =
                CreateApiResponseResult <BaseResponse>(result.Value, result.StatusCode);
            ActionableFailureApiResultEventArgs eventArgs = new(baseResponseResult);

            OnActionableFailureResult?.Invoke(this, eventArgs);
        }
Ejemplo n.º 5
0
        protected ApiResponseResult <T> ApiResponseResult <T>(string body, HttpStatusCode code)
            where T : BaseResponse
        {
            try
            {
                T response = JsonConvert.DeserializeObject <T>(body);
                if (response == null)
                {
                    throw new HttpRequestException(string.Empty);
                }

                ApiResponseResult <T> result = CreateApiResponseResult(response, code);
                HandleResult(result);
                return(result);
            }
            catch (JsonException)
            {
                throw new HttpRequestException(code.Description());
            }
        }
Ejemplo n.º 6
0
 public static ApiResponseResult <T> Fail <TOther>(ApiResponseResult <TOther> other)
     where TOther : BaseResponse
 {
     return(new ApiResponseResult <T>(other.StatusCode, false, other.Value));
 }
 public ActionableFailureApiResultEventArgs(ApiResponseResult <BaseResponse> result)
 {
     Result = result;
 }