public void BadResponse <TReturn>(ref ElasticsearchResponse <TReturn> response, RequestData data, List <PipelineException> pipelineExceptions) where TReturn : class { var callDetails = response ?? pipelineExceptions.LastOrDefault()?.Response; var pipelineFailure = data.OnFailurePipelineFailure; if (pipelineExceptions.HasAny()) { pipelineFailure = pipelineExceptions.Last().FailureReason; } var innerException = pipelineExceptions.HasAny() ? new AggregateException(pipelineExceptions) : callDetails?.OriginalException; var exceptionMessage = innerException?.Message ?? "Could not complete the request to Elasticsearch."; if (this.IsTakingTooLong) { pipelineFailure = PipelineFailure.MaxTimeoutReached; this.Audit(MaxTimeoutReached); exceptionMessage = "Maximum timeout reached while retrying request"; } else if (this.Retried >= this.MaxRetries && this.MaxRetries > 0) { pipelineFailure = PipelineFailure.MaxRetriesReached; this.Audit(MaxRetriesReached); exceptionMessage = "Maximum number of retries reached."; } var clientException = new ElasticsearchClientException(pipelineFailure, exceptionMessage, innerException) { Request = data, Response = callDetails, AuditTrail = this.AuditTrail }; if (_settings.ThrowExceptions) { this._settings.OnRequestCompleted?.Invoke(clientException.Response); throw clientException; } if (response == null) { response = new ResponseBuilder <TReturn>(data) { StatusCode = callDetails?.HttpStatusCode, Exception = clientException }.ToResponse(); } if (callDetails?.ResponseBodyInBytes != null && response.ResponseBodyInBytes == null) { response.ResponseBodyInBytes = callDetails.ResponseBodyInBytes; } if (callDetails?.ServerError != null && response.ServerError == null) { response.ServerError = callDetails.ServerError; } response.AuditTrail = this.AuditTrail; }
private DesignIssueWarning getDesignIssueWarningForObjectNamedWithReservedWordssignIssueWarning(Model.Database database) { DesignIssueWarning warning = new DesignIssueWarning() { Description = "Database object names should not be reserved words", ReferenceUrl = new Uri("https://msdn.microsoft.com/en-us/library/ms189822(SQL.100).aspx") }; if (database == null) { return null; //cannot act on empty object } List<IDbObject> objectList = new List<IDbObject>(); if (this.reservedWords.Contains(database.ObjectName, StringComparer.OrdinalIgnoreCase)) { objectList.Add(database as IDbObject); } IList<IDbObject> allDbObjList = database.GetAllObjects(); // union objects to one collection to get one list to parse var nameViolations = ( from obj in allDbObjList where this.reservedWords.Contains(obj.ObjectName, StringComparer.OrdinalIgnoreCase) orderby obj.ObjectFullDisplayName select obj ).ToList(); objectList.AddRange(nameViolations); //do we have any objects? if (objectList.HasAny()) { warning.DatabaseObjects = objectList; } else { warning = null; } return warning; }
public ElasticsearchClientException CreateClientException <TResponse>( TResponse response, IApiCallDetails callDetails, RequestData data, List <PipelineException> pipelineExceptions ) where TResponse : class, IElasticsearchResponse, new() { if (callDetails?.Success ?? false) { return(null); } var innerException = pipelineExceptions.HasAny() ? pipelineExceptions.AsAggregateOrFirst() : callDetails?.OriginalException; var statusCode = callDetails?.HttpStatusCode != null?callDetails.HttpStatusCode.Value.ToString() : "unknown"; var resource = callDetails == null ? "unknown resource" : $"Status code {statusCode} from: {callDetails.HttpMethod} {callDetails.Uri.PathAndQuery}"; var exceptionMessage = innerException?.Message ?? "Request failed to execute"; var pipelineFailure = data.OnFailurePipelineFailure; if (pipelineExceptions.HasAny()) { pipelineFailure = pipelineExceptions.Last().FailureReason; } if (IsTakingTooLong) { pipelineFailure = PipelineFailure.MaxTimeoutReached; Audit(MaxTimeoutReached); exceptionMessage = "Maximum timeout reached while retrying request"; } else if (Retried >= MaxRetries && MaxRetries > 0) { pipelineFailure = PipelineFailure.MaxRetriesReached; Audit(MaxRetriesReached); exceptionMessage = "Maximum number of retries reached"; var now = _dateTimeProvider.Now(); var activeNodes = _connectionPool.Nodes.Count(n => n.IsAlive || n.DeadUntil <= now); if (Retried >= activeNodes) { Audit(FailedOverAllNodes); exceptionMessage += ", failed over to all the known alive nodes before failing"; } } exceptionMessage += $". Call: {resource}"; if (response != null && response.TryGetServerErrorReason(out var reason)) { exceptionMessage += $". ServerError: {reason}"; } var clientException = new ElasticsearchClientException(pipelineFailure, exceptionMessage, innerException) { Request = data, Response = callDetails, AuditTrail = AuditTrail }; return(clientException); }
private DesignIssueWarning getDesignIssueForObjectsWithSpecialCharactersInName(Model.Database database) { DesignIssueWarning warning = new DesignIssueWarning() { Description = "Database object names should not contain special characters", ReferenceUrl = new Uri("https://msdn.microsoft.com/en-us/library/dd172134(v=vs.100).aspx") }; if (database == null) { return null; //cannot act on empty object } List<IDbObject> objectList = new List<IDbObject>(); // check Db name if (this.checkForSpecialCharacters(database.ObjectName)) { objectList.Add(database); } IList<IDbObject> allDbObjList = database.GetAllObjects(); foreach (IDbObject obj in allDbObjList) { if (this.checkForSpecialCharacters(obj.ObjectName)) { objectList.Add(obj); } } //do we have any objects? if (objectList.HasAny()) { warning.DatabaseObjects = objectList; } else { warning = null; } return warning; }