Exemplo n.º 1
0
 public void OnError(IApiError error)
 {
     if (_scene.IsLoginOrRegister)
     {
         return;
     }
     _scene.GoToStart();
     _state.User  = null;
     _state.State = null;
 }
        public object Invoke(MethodInfo methodInfo, object arguments, Func <object> method)
        {
            Type returnType = methodInfo.ReturnType;

            IApiResponse response = (IApiResponse)Activator.CreateInstance(returnType);

            try
            {
                IApiResult result = response as IApiResult;
                if (result != null)
                {
                    result.Data = method.Invoke();
                }
                else
                {
                    method.Invoke();
                }

                response.IsSuccess = true;
                return(response);
            }
            catch (ValidationException exception)
            {
                response.ValidationErrors = exception.Errors;
            }
            catch (BusinessException exception)
            {
                response.ErrorMessage = exception.Message;

                IApiError error = response as IApiError;
                if (error != null)
                {
                    error.ErrorCode = exception.Code;
                }
            }
            catch (Exception exception)
            {
                response.ErrorMessage = exception.Message;

                IBusinessException businessException = exception as IBusinessException;
                if (businessException != null)
                {
                    IApiError error = response as IApiError;
                    if (error != null)
                    {
                        error.ErrorCode = businessException.Code;
                    }
                }
            }

            response.IsSuccess = false;
            return(response);
        }
        private static string GetDetailedErrorMessage(int statusCode, IApiError error)
        {
            var baseMessage = $"{error.ErrorSummary} ({statusCode}, {error.ErrorCode})";

            var hasErrorCauses = error?.ErrorCauses?.Any() ?? false;

            if (!hasErrorCauses)
            {
                return(baseMessage);
            }

            var causes = string.Join(", ", error.ErrorCauses.Select(x => $"{x.ErrorSummary}"));

            return($"{baseMessage}: {causes}");
        }
Exemplo n.º 4
0
        public async Task Advise(MethodAsyncAdviceContext context)
        {
            MethodInfo methodInfo = (MethodInfo)context.TargetMethod;
            Type       returnType = methodInfo.ReturnType.GetGenericArguments()[0];

            IApiResponse response;

            try
            {
                await context.ProceedAsync();

                return;
            }
            catch (ValidationException exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ValidationErrors = exception.Errors;
            }
            catch (BusinessException exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ErrorMessage = exception.Message;

                IApiError error = response as IApiError;
                if (error != null)
                {
                    error.ErrorCode = exception.Code;
                }
            }
            catch (Exception exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ErrorMessage = exception.Message;

                IBusinessException businessException = exception as IBusinessException;
                if (businessException != null)
                {
                    IApiError error = response as IApiError;
                    if (error != null)
                    {
                        error.ErrorCode = businessException.Code;
                    }
                }
            }

            response.IsSuccess  = false;
            context.ReturnValue = Task.FromResult(response);
        }
Exemplo n.º 5
0
        public void Advise(MethodAdviceContext context)
        {
            MethodInfo methodInfo = (MethodInfo)context.TargetMethod;
            Type       returnType = methodInfo.ReturnType;

            IApiResponse response;

            try
            {
                context.Proceed();
                return;
            }
            catch (ValidationException exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ValidationErrors = exception.Errors;
            }
            catch (BusinessException exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ErrorMessage = exception.Message;

                IApiError error = response as IApiError;
                if (error != null)
                {
                    error.ErrorCode = exception.Code;
                }
            }
            catch (Exception exception)
            {
                response = (IApiResponse)Activator.CreateInstance(returnType);
                response.ErrorMessage = exception.Message;

                IBusinessException businessException = exception as IBusinessException;
                if (businessException != null)
                {
                    IApiError error = response as IApiError;
                    if (error != null)
                    {
                        error.ErrorCode = businessException.Code;
                    }
                }
            }

            response.IsSuccess  = false;
            context.ReturnValue = response;
        }
Exemplo n.º 6
0
 public static ApiResponse <T> AsError <T>(this IApiError error)
 {
     return(new ApiResponse <T>(default, error));
 /// <summary>
 /// Initializes a new instance of the <see cref="OktaApiException"/> class.
 /// </summary>
 /// <param name="statusCode">The HTTP status code.</param>
 /// <param name="error">The error data.</param>
 public OktaApiException(int statusCode, IApiError error)
     : base(GetDetailedErrorMessage(statusCode, error), statusCode)
 {
     _error = error;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OktaApiException"/> class.
 /// </summary>
 /// <param name="statusCode">The HTTP status code.</param>
 /// <param name="error">The error data.</param>
 public OktaApiException(int statusCode, IApiError error)
     : base(message: GetDetailedErrorMessage(statusCode, error))
 {
     StatusCode = statusCode;
     _error     = error;
 }
Exemplo n.º 9
0
 public void OnError(IApiError error)
 {
 }
 public void OnError(IApiError error)
 {
     _logger.Error(this, $"Failed: '{error.Message}' ({error.GetType().Name})");
     Environment.Exit(-1);
 }
Exemplo n.º 11
0
        void OnApiError(IApiError obj)
        {
            var message = !string.IsNullOrEmpty(obj.Message) ? obj.Message : obj.GetType().Name;

            _notice.ScheduleNotice(new NoticeModel(message, _ => _scene.GoToStart()));
        }
Exemplo n.º 12
0
 public void OnError(IApiError error)
 {
     throw new InvalidOperationException(error.Message);
 }
Exemplo n.º 13
0
 public ApiResponse(T result, IApiError error)
 {
     Result = result;
     Error  = error;
 }