public static QueryResponseCore CreateFromException(Exception exception) { QueryResponseCore queryResponseCore; if (exception is CosmosException cosmosException) { queryResponseCore = CreateFromCosmosException(cosmosException); } else if (exception is Microsoft.Azure.Documents.DocumentClientException documentClientException) { queryResponseCore = CreateFromDocumentClientException(documentClientException); } else if (exception is QueryException queryException) { CosmosException convertedException = queryException.Accept(QueryExceptionConverter.Singleton); queryResponseCore = CreateFromCosmosException(convertedException); } else if (exception is ExceptionWithStackTraceException exceptionWithStackTrace) { queryResponseCore = QueryResponseFactory.CreateFromExceptionWithStackTrace(exceptionWithStackTrace); } else { if (exception.InnerException != null) { // retry with the inner exception queryResponseCore = QueryResponseFactory.CreateFromException(exception.InnerException); } else { CosmosException unkownCosmosException = CosmosExceptionFactory.CreateInternalServerErrorException( subStatusCode: default,
public static QueryResponseCore CreateFromException(Exception exception) { QueryResponseCore queryResponseCore; if (exception is CosmosException cosmosException) { queryResponseCore = CreateFromCosmosException(cosmosException); } else if (exception is Microsoft.Azure.Documents.DocumentClientException documentClientException) { queryResponseCore = CreateFromDocumentClientException(documentClientException); } else if (exception is QueryException queryException) { CosmosException convertedException = queryException.Accept(QueryExceptionConverter.Singleton); queryResponseCore = CreateFromCosmosException(convertedException); } else if (exception is ExceptionWithStackTraceException exceptionWithStackTrace) { queryResponseCore = QueryResponseFactory.CreateFromExceptionWithStackTrace(exceptionWithStackTrace); } else { if (exception.InnerException != null) { // retry with the inner exception queryResponseCore = QueryResponseFactory.CreateFromException(exception.InnerException); } else { CosmosException unkownCosmosException = CosmosExceptionFactory.CreateInternalServerErrorException( headers: new Headers() { SubStatusCode = SubStatusCodes.PartitionKeyRangeGone, ActivityId = QueryResponseCore.EmptyGuidString }, message: exception.Message, stackTrace: exception.StackTrace, trace: NoOpTrace.Singleton, innerException: exception); // Unknown exception type should become a 500 queryResponseCore = QueryResponseCore.CreateFailure( statusCode: System.Net.HttpStatusCode.InternalServerError, subStatusCodes: null, cosmosException: unkownCosmosException, requestCharge: 0, activityId: QueryResponseCore.EmptyGuidString); } } return(queryResponseCore); }