diff --git a/ConnectorArchicad/ConnectorArchicad/Communication/AsyncCommandProcessor.cs b/ConnectorArchicad/ConnectorArchicad/Communication/AsyncCommandProcessor.cs index c0a20ce18f..4061077508 100644 --- a/ConnectorArchicad/ConnectorArchicad/Communication/AsyncCommandProcessor.cs +++ b/ConnectorArchicad/ConnectorArchicad/Communication/AsyncCommandProcessor.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Speckle.Core.Logging; namespace Archicad.Communication; @@ -27,10 +28,15 @@ internal class AsyncCommandProcessor { return Task.Run(command.Execute, token); } - catch (Exception e) + catch (ArgumentNullException) { return null; } + catch (Exception ex) when (ex is TaskCanceledException or ObjectDisposedException) + { + SpeckleLog.Logger.Error(ex, "Could not communicate with Archicad."); + return null; + } } #endregion diff --git a/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs b/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs index ea86789727..97f32adba6 100644 --- a/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs +++ b/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs @@ -174,22 +174,14 @@ public override async Task ReceiveStream(StreamState state, Progres } } } - catch (Exception ex) + catch (SpeckleException) { - // log - if (ex is not OperationCanceledException) - { - SpeckleLog.Logger.Error("Conversion to native failed."); - } - - // throw - switch (ex) - { - case OperationCanceledException: - throw new OperationCanceledException(ex.Message); - default: - throw new SpeckleException(ex.Message, ex); - } + SpeckleLog.Logger.Error("Conversion to native failed."); + throw; + } + catch (OperationCanceledException) + { + throw; } return state; diff --git a/ConnectorArchicad/ConnectorArchicad/Converters/ElementConverterManagerReceive.cs b/ConnectorArchicad/ConnectorArchicad/Converters/ElementConverterManagerReceive.cs index 5ab5e5eb7a..d70823dfe0 100644 --- a/ConnectorArchicad/ConnectorArchicad/Converters/ElementConverterManagerReceive.cs +++ b/ConnectorArchicad/ConnectorArchicad/Converters/ElementConverterManagerReceive.cs @@ -26,14 +26,14 @@ CancellationToken token var elementConverter = GetConverterForElement(elementType, conversionOptions, true); return await elementConverter.ConvertToArchicad(elements, token); } - catch (OperationCanceledException) + catch (Exception ex) when (ex is SpeckleException or ArgumentNullException or ObjectDisposedException) { - throw; + SpeckleLog.Logger.Warning(ex, "Failed to convert element type {elementType}", elementType.ToString()); + return null; } - catch (Exception) + catch (OperationCanceledException) { - SpeckleLog.Logger.Warning("Failed to convert element type {elementType}", elementType.ToString()); - return null; + throw; } }