public void ReportInitializationError(Exception exception)
        {
            this.LogDebug($"Creating ExceptionResponse from {exception?.GetType().Name} exception");

            var json = ToJson(ExceptionResponse.Create(exception));

            this.LogDebug("Reporting invocation error");

            using (var response = _http.PostAsync("init/error",
                                                  new StringContent(json)).GetAwaiter().GetResult())
            {
                this.LogDebug($"Response status code is {(int)response.StatusCode}");

                if (response.StatusCode != HttpStatusCode.Accepted)
                {
                    Console.WriteLine("Failed to report initialization error");
                }
            }
        }
        public static ExceptionResponse Create(Exception ex)
        {
            var response = new ExceptionResponse();

            if (ex != null)
            {
                response.ErrorType      = ex.GetType().Name;
                response.ErrorMessage   = ex.Message;
                response.StackTrace     = ex.StackTrace?.Split('\n').ToArray();
                response.InnerException = ex.InnerException != null?Create(ex) : null;

                if (ex is AggregateException aggregateException)
                {
                    response.InnerExceptions =
                        aggregateException.InnerExceptions?.Select(Create).ToArray();
                }
            }

            return(response);
        }