示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnauthorizedTokenException" /> class.
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="hint">The hint.</param>
 /// <param name="scene">The scene.</param>
 public UnauthorizedTokenException(object data = null, FriendlyHint hint = null, ExceptionScene scene = null)
     : base("Unauthorized token or token expired.", new ExceptionCode {
     Major = ExceptionCode.MajorCode.UnauthorizedOperation, Minor = "Token"
 }, null, data, hint, scene)
 {
 }
        /// <summary>
        /// Handles the exception.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="scene">The scene.</param>
        /// <param name="data">The data.</param>
        /// <param name="hint">The hint.</param>
        /// <param name="minorCode">The minor code.</param>
        /// <returns>
        /// BaseServiceException.
        /// </returns>
        internal static BaseException Handle(this Exception exception, ExceptionScene scene, object data = null, FriendlyHint hint = null, string minorCode = null)
        {
            TargetInvocationException targetInvocationException = exception as TargetInvocationException;

            if (targetInvocationException != null)
            {
                return(targetInvocationException.InnerException.Handle(scene, data, hint, minorCode));
            }
            else
            {
                var baseException = exception as BaseException;
                var operationName = scene?.MethodName;

                if (baseException != null)
                {
                    if (string.IsNullOrWhiteSpace(operationName))
                    {
                        return(baseException);
                    }
                    else
                    {
                        switch (baseException.Code.Major)
                        {
                        case ExceptionCode.MajorCode.UnauthorizedOperation:
                            return(new UnauthorizedOperationException(baseException, minorCode.SafeToString(baseException.Code.Minor), data, scene: scene) as BaseException);

                        case ExceptionCode.MajorCode.OperationForbidden:
                            return(new OperationForbiddenException(operationName, minorCode.SafeToString(baseException.Code?.Minor), baseException, data, scene: scene) as BaseException);

                        case ExceptionCode.MajorCode.NullOrInvalidValue:
                        case ExceptionCode.MajorCode.DataConflict:
                        case ExceptionCode.MajorCode.NotImplemented:
                        case ExceptionCode.MajorCode.ResourceNotFound:
                        case ExceptionCode.MajorCode.CreditNotAfford:
                        case ExceptionCode.MajorCode.ServiceUnavailable:
                            return(baseException);

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    var sqlException = exception as SqlException;

                    if (sqlException != null)
                    {
                        return(new OperationFailureException(exception, data, hint: hint, scene: scene, minor: minorCode) as BaseException);
                    }
                    else
                    {
                        var notImplementException = exception as NotImplementedException;

                        if (notImplementException != null)
                        {
                            return(new UnimplementedException(operationName, notImplementException));
                        }
                    }
                }

                return(new OperationFailureException(exception, data, scene: scene, minor: minorCode) as BaseException);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UnauthorizedTokenException" /> class.
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="hint">The hint.</param>
 /// <param name="scene">The scene.</param>
 public UnauthorizedTokenException(object data = null, FriendlyHint hint = null, ExceptionScene scene = null)
     : base("Unauthorized token or token expired.", new ExceptionCode { Major = ExceptionCode.MajorCode.UnauthorizedOperation, Minor = "Token" }, null, data, hint, scene)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NullObjectException" /> class.
 /// </summary>
 /// <param name="objectIdentity">The object identity.</param>
 /// <param name="friendlyHint">The friendly hint.</param>
 /// <param name="scene">The scene.</param>
 public NullObjectException(string objectIdentity, FriendlyHint friendlyHint = null, ExceptionScene scene = null)
     : base(string.Format("[{0}] is null.", objectIdentity), new ExceptionCode {
     Major = ExceptionCode.MajorCode.NullOrInvalidValue, Minor = "NullObject"
 }, null, null, hint: friendlyHint, scene: scene)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UnauthorizedOperationException" /> class.
 /// </summary>
 /// <param name="reason">The reason.</param>
 /// <param name="data">The data.</param>
 /// <param name="hint">The hint.</param>
 /// <param name="scene">The scene.</param>
 public UnauthorizedAccountException(string reason, object data = null, FriendlyHint hint = null, ExceptionScene scene = null)
     : base(string.Format("Failed to authenticate account caused by [{0}].", reason), new ExceptionCode { Major = ExceptionCode.MajorCode.UnauthorizedOperation, Minor = reason.SafeToString("Account") }, data: data, hint: hint, scene: scene)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UnauthorizedOperationException" /> class.
 /// </summary>
 /// <param name="reason">The reason.</param>
 /// <param name="data">The data.</param>
 /// <param name="hint">The hint.</param>
 /// <param name="scene">The scene.</param>
 public UnauthorizedAccountException(string reason, object data = null, FriendlyHint hint = null, ExceptionScene scene = null)
     : base(string.Format("Failed to authenticate account caused by [{0}].", reason), new ExceptionCode {
     Major = ExceptionCode.MajorCode.UnauthorizedOperation, Minor = reason.SafeToString("Account")
 }, data: data, hint: hint, scene: scene)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NullObjectException" /> class.
 /// </summary>
 /// <param name="objectIdentity">The object identity.</param>
 /// <param name="scene">The scene.</param>
 public NullObjectException(string objectIdentity, ExceptionScene scene = null)
     : base(string.Format("[{0}] is null.", objectIdentity), new ExceptionCode { Major = ExceptionCode.MajorCode.NullOrInvalidValue, Minor = "NullObject" }, null, null, scene: scene)
 {
 }