mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
* Revert "Update SMO (#875)" This reverts commit96593d66e3. * Revert "Switch Tools Service to new SMO and Microsoft.Data.SqlClient driver (#865)" This reverts commit9d140b53f3. * Bump SMO to 160.1910315.0-preview
70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
using System;
|
|
using System.Data.Common;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
|
|
namespace Microsoft.SqlTools.ResourceProvider.Core
|
|
{
|
|
/// <summary>
|
|
/// Extension methods and utils for exceptions
|
|
/// </summary>
|
|
internal static class ExceptionUtil
|
|
{
|
|
/// <summary>
|
|
/// Returns true if given exception if any of the inner exceptions is UserNeedsAuthenticationException
|
|
/// </summary>
|
|
internal static bool IsUserNeedsReauthenticateException(this Exception ex)
|
|
{
|
|
return ex.IsExceptionType(typeof(UserNeedsAuthenticationException));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns true if given exception if any of the inner exceptions is sql exception
|
|
/// </summary>
|
|
internal static bool IsDbException(this Exception ex)
|
|
{
|
|
return ex.IsExceptionType(typeof (DbException));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns true if given exception if any of the inner exceptions is same type of given type
|
|
/// </summary>
|
|
internal static bool IsExceptionType(this Exception ex, Type type)
|
|
{
|
|
if (ex == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (ex is AggregateException)
|
|
{
|
|
var aggregateException = (AggregateException)ex;
|
|
return aggregateException.InnerExceptions != null &&
|
|
aggregateException.InnerExceptions.Any(inner => inner.IsExceptionType(type));
|
|
}
|
|
else if (type.IsAssignableFrom(ex.GetType()) || (ex.InnerException != null && ex.InnerException.IsExceptionType(type)))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal static string GetExceptionMessage(this Exception ex)
|
|
{
|
|
string errorMessage = string.Empty;
|
|
if (ex != null)
|
|
{
|
|
errorMessage = ex.Message;
|
|
if (ex.InnerException != null)
|
|
{
|
|
errorMessage += " " + ex.InnerException.Message;
|
|
}
|
|
}
|
|
return errorMessage;
|
|
}
|
|
}
|
|
}
|