diff --git a/Box.V2/Exceptions/BoxAuthenticationFailedException.cs b/Box.V2/Exceptions/BoxAuthenticationFailedException.cs index 52255a84c..d321a68aa 100644 --- a/Box.V2/Exceptions/BoxAuthenticationFailedException.cs +++ b/Box.V2/Exceptions/BoxAuthenticationFailedException.cs @@ -24,9 +24,8 @@ protected internal BoxSessionInvalidatedException(string message, BoxError error protected internal static new BoxSessionInvalidatedException GetResponseException(string message, IBoxResponse response) where T : class { - var ex = BoxAPIException.GetResponseException(message, response); - - return (BoxSessionInvalidatedException)ex; + var error = GetResponseError(response); + return new BoxSessionInvalidatedException(GetErrorMessage(message, response, error), response.Error, response.StatusCode, response.Headers); } } } diff --git a/Box.V2/Exceptions/BoxException.cs b/Box.V2/Exceptions/BoxException.cs index a5611359e..934888b2b 100644 --- a/Box.V2/Exceptions/BoxException.cs +++ b/Box.V2/Exceptions/BoxException.cs @@ -61,6 +61,12 @@ protected internal BoxAPIException(string message, BoxError error, HttpStatusCod /// The message from the SDK about what happened /// The HTTP response that generated the exception protected internal static BoxAPIException GetResponseException(string message, IBoxResponse response) where T : class + { + var error = GetResponseError(response); + return new BoxAPIException(GetErrorMessage(message, response, error), response.Error, response.StatusCode, response.Headers); + } + + protected internal static BoxError GetResponseError(IBoxResponse response) where T : class { BoxError error = null; if (!string.IsNullOrWhiteSpace(response.ContentString)) @@ -76,12 +82,11 @@ protected internal BoxAPIException(string message, BoxError error, HttpStatusCod Debug.WriteLine(string.Format("Unable to parse error message: {0} ({1})", response.ContentString, e.Message)); } } - var ex = new BoxAPIException(GetErrorMessage(message, response, error), response.Error, response.StatusCode, response.Headers); - return ex; + return error; } - private static string GetErrorMessage(string message, IBoxResponse response, BoxError error = null) where T : class + protected internal static string GetErrorMessage(string message, IBoxResponse response, BoxError error = null) where T : class { var requestID = error?.RequestId; string traceID = null;