Ejemplo n.º 1
0
            public static ErrorCodes HandleClientException(IClientException <ErrorData> exception)
            {
                Console.Clear();
                var res = HandleClientExceptionErrorData(exception);

                PrettyConsole.WriteLineColor(ConsoleColor.Red, "Ошибка: {0}", res.Item2);
                return(res.Item1);
            }
Ejemplo n.º 2
0
            private static Tuple <ErrorCodes, string> HandleClientExceptionErrorData <T>(IClientException <T> exception)
                where T : ErrorData
            {
                ErrorCodes errorCodes = ErrorCodes.OtherError;
                string     errorData  = string.Empty;

                if (exception.ErrorData != null)
                {
                    errorData = exception.ErrorData.Message;
                    var authException = exception as ClientException <WrongAuthData <PasswordAuthData> >;
                    if (authException != null)
                    {
                        errorCodes = ErrorCodes.AuthError;
                        errorData += string.Format(" Login {0} not exists or wrong password", authException.ErrorData.RequestData.Usename);
                    }

                    var validationData = exception.ErrorData as ValidationErrorData;
                    if (validationData != null)
                    {
                        errorCodes = ErrorCodes.ValidationError;
                        errorData += validationData.ModelState;
                    }

                    var invalidSessionException = exception.ErrorData as InvalidSessionException;
                    if (invalidSessionException != null)
                    {
                        errorCodes = ErrorCodes.InvalidSessionError;
                        errorData += invalidSessionException.ErrorData.SessionGuid;
                    }

                    var clientExceptionWithServerErrorData = exception.ErrorData as ClientException <ServerErrorData>;
                    if (clientExceptionWithServerErrorData != null)
                    {
                        errorCodes = ErrorCodes.ServerError;
                        errorData += clientExceptionWithServerErrorData.ErrorData.StackTrace;
                    }
                }
                return(Tuple.Create(errorCodes, errorData));
            }