private static string GetMessageHelper(
            HttpStatusCode statusCode,
            Headers headers,
            string responseBody,
            CosmosDiagnostics diagnostics)
        {
            StringBuilder stringBuilder = new StringBuilder();

            CosmosException.AppendMessageWithoutDiagnostics(
                stringBuilder,
                statusCode,
                headers,
                responseBody);

            // Include the diagnostics for exceptions where it is critical
            // to root cause failures.
            if (statusCode == HttpStatusCode.RequestTimeout ||
                statusCode == HttpStatusCode.InternalServerError ||
                statusCode == HttpStatusCode.ServiceUnavailable ||
                (statusCode == HttpStatusCode.NotFound && headers.SubStatusCode == SubStatusCodes.ReadSessionNotAvailable))
            {
                stringBuilder.Append("; Diagnostics:");
                stringBuilder.Append(diagnostics.ToString());
            }

            return(stringBuilder.ToString());
        }
        private string ToStringHelper(
            StringBuilder stringBuilder)
        {
            if (stringBuilder == null)
            {
                throw new ArgumentNullException(nameof(stringBuilder));
            }

            CosmosException.AppendMessageWithoutDiagnostics(
                stringBuilder,
                this.StatusCode,
                this.Headers,
                this.ResponseBody);
            stringBuilder.AppendLine();

            if (this.InnerException != null)
            {
                stringBuilder.Append(" ---> ");
                stringBuilder.Append(this.InnerException);
                stringBuilder.AppendLine();
                stringBuilder.Append("   ");
                stringBuilder.Append("--- End of inner exception stack trace ---");
                stringBuilder.AppendLine();
            }

            if (this.StackTrace != null)
            {
                stringBuilder.Append(this.StackTrace);
                stringBuilder.AppendLine();
            }

            if (this.Diagnostics != null)
            {
                stringBuilder.Append("--- Cosmos Diagnostics ---");
                stringBuilder.Append(this.Diagnostics);
            }

            return(stringBuilder.ToString());
        }