fix: new exception classes

This commit is contained in:
Damien 2025-03-01 13:49:57 -05:00
parent d3c4be572b
commit 38444d5cd5
17 changed files with 122 additions and 5 deletions

View File

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using meilisearch.NET;
using meilisearch.NET.Configurations;
using meilisearch.NET.example;
using meilisearch.NET.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

View File

@ -0,0 +1,12 @@
namespace meilisearch.NET.Exceptions;
public class DocumentBatchException : DocumentManagementException
{
public int BatchSize { get; }
public DocumentBatchException(int batchSize, Exception innerException)
: base($"Failed to process batch of {batchSize} documents", innerException)
{
BatchSize = batchSize;
}
}

View File

@ -0,0 +1,10 @@
namespace meilisearch.NET.Exceptions;
/// <summary>
/// Exception thrown when there are issues with document management
/// </summary>
public class DocumentManagementException : MeiliSearchException
{
public DocumentManagementException(string message) : base(message) { }
public DocumentManagementException(string message, Exception innerException) : base(message, innerException) { }
}

View File

@ -0,0 +1,7 @@
namespace meilisearch.NET.Exceptions;
public class DocumentSyncException : DocumentManagementException
{
public DocumentSyncException(string message, Exception innerException)
: base($"Failed to sync documents: {message}", innerException) { }
}

View File

@ -0,0 +1,7 @@
namespace meilisearch.NET.Exceptions;
public class DocumentValidationException : DocumentManagementException
{
public DocumentValidationException(string message)
: base($"Document validation failed: {message}") { }
}

View File

@ -0,0 +1,12 @@
namespace meilisearch.NET.Exceptions;
public class IndexCompressionException : IndexManagementException
{
public string IndexName { get; }
public IndexCompressionException(string indexName, string operation, Exception innerException)
: base($"Failed to {operation} index '{indexName}'", innerException)
{
IndexName = indexName;
}
}

View File

@ -0,0 +1,7 @@
namespace meilisearch.NET.Exceptions;
public class IndexLimitExceededException : IndexManagementException
{
public IndexLimitExceededException()
: base("Maximum number of indexes (1000) has been reached") { }
}

View File

@ -0,0 +1,10 @@
namespace meilisearch.NET.Exceptions;
/// <summary>
/// Exception thrown when there are issues with index management
/// </summary>
public class IndexManagementException : MeiliSearchException
{
public IndexManagementException(string message) : base(message) { }
public IndexManagementException(string message, Exception innerException) : base(message, innerException) { }
}

View File

@ -0,0 +1,12 @@
namespace meilisearch.NET.Exceptions;
public class IndexNotFoundException : IndexManagementException
{
public string IndexName { get; }
public IndexNotFoundException(string indexName)
: base($"Index '{indexName}' not found")
{
IndexName = indexName;
}
}

View File

@ -0,0 +1,10 @@
namespace meilisearch.NET.Exceptions;
/// <summary>
/// Base exception class for all Meilisearch.NET exceptions
/// </summary>
public class MeiliSearchException : Exception
{
public MeiliSearchException(string message) : base(message) { }
public MeiliSearchException(string message, Exception innerException) : base(message, innerException) { }
}

View File

@ -0,0 +1,10 @@
namespace meilisearch.NET.Exceptions;
/// <summary>
/// Exception thrown when there are issues with the Meilisearch process management
/// </summary>
public class ProcessManagementException : MeiliSearchException
{
public ProcessManagementException(string message) : base(message) { }
public ProcessManagementException(string message, Exception innerException) : base(message, innerException) { }
}

View File

@ -0,0 +1,6 @@
namespace meilisearch.NET.Exceptions;
public class ProcessNotRunningException : ProcessManagementException
{
public ProcessNotRunningException() : base("Meilisearch process is not running") { }
}

View File

@ -0,0 +1,6 @@
namespace meilisearch.NET.Exceptions;
public class ProcessStartException : ProcessManagementException
{
public ProcessStartException(string message) : base($"Failed to start Meilisearch process: {message}") { }
}

View File

@ -0,0 +1,6 @@
namespace meilisearch.NET.Exceptions;
public class ProcessStopException : ProcessManagementException
{
public ProcessStopException(string message) : base($"Failed to stop Meilisearch process: {message}") { }
}

View File

@ -1,6 +1,6 @@
using Meilisearch;
using meilisearch.NET;
using meilisearch.NET.Models;
namespace meilisearch.NET.Extensions;
public static class MeilisearchClientExtensions
{

View File

@ -1,11 +1,12 @@
using Meilisearch;
using meilisearch.NET;
using meilisearch.NET.Configurations;
using meilisearch.NET.Services.DocumentManagement;
using meilisearch.NET.Services.IndexManagement;
using meilisearch.NET.Services.ProcessManagement;
using Microsoft.Extensions.DependencyInjection;
namespace meilisearch.NET.Extensions;
public static class ServiceCollectionExtension
{
public static IServiceCollection AddMeiliSearchService(this IServiceCollection services)
@ -22,4 +23,4 @@ public static class ServiceCollectionExtension
services.AddSingleton<MeiliSearchService>();
return services;
}
}
}

View File

@ -29,7 +29,7 @@ public class DocumentManager:IDocumentManager
_logger.LogInformation($"Document {document.Id} added to collection.");
if (autoCommit)
{
SyncDocumentsToServer();
await SyncDocumentsToServerAsync();
}
}
public void AddDocument(string repositoryId, IDocument document, bool autoCommit = false)