/// <summary> /// This method *has* to convert whatever NHibernate exception to a valid PPWCode exception /// Some hibernate exceptions might be semantic, some might be errors. /// This may depend on the actual product. /// This method translates semantic exceptions in PPWCode.Util.Exception.SemanticException and throws them /// and all other exceptions in PPWCode.Util.Exception.Error and throws them. /// </summary> /// <param name="exception">The hibernate exception we are triaging.</param> /// <param name="message">This message will be used in the logging in the case aException = Error.</param> /// <returns>An exception that is a sub class either from <see cref="SemanticException" /> or from <see cref="Error" />.</returns> protected virtual Exception TriageException(Exception exception, string message) { Contract.Requires(exception != null); Contract.Requires(!string.IsNullOrEmpty(message)); Exception result; Logger.Debug(message, exception); GenericADOException genericAdoException = exception as GenericADOException; if (genericAdoException != null) { RepositorySqlException repositorySqlException = new RepositorySqlException(message, genericAdoException.InnerException) { SqlString = genericAdoException.SqlString, }; SqlException sqlException = genericAdoException.InnerException as SqlException; if (sqlException != null) { repositorySqlException.Constraint = sqlException.GetConstraint(); } result = repositorySqlException; } else { result = new ExternalError(message, exception); } throw result; }
public static bool IsDuplicateKey(this GenericADOException exception) { return(exception.InnerException is SqlException inner && inner.Number == 2601); }
public void Mark_nhibernate_adonet_wrapped_exceptions_as_transient() { var e = new GenericADOException("Wrapped exception", SqlExceptionGenerator.GetSqlException(40197)); Assert.That(new TTransientErrorDetectionStrategy().IsTransient(e)); }
public void Mark_wrapped_timeout_exception_as_transient([Values(-2, 121)] int errorCode) { var e = new GenericADOException("Wrapped exception", SqlExceptionGenerator.GetSqlException(errorCode)); Assert.That(new SqlAzureTransientErrorDetectionStrategyWithTimeouts().IsTransient(e)); }