From 896e4b89d6285134064f83e4c277537f105b4f90 Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Sat, 13 Dec 2025 17:36:51 +0100 Subject: [PATCH] Improved logging for EntityResults --- src/Server/Controllers/EntityController.cs | 22 +++++++++++++++------- src/Shared/Models/EntityResults.cs | 6 ++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Server/Controllers/EntityController.cs b/src/Server/Controllers/EntityController.cs index 12f9176..4765311 100644 --- a/src/Server/Controllers/EntityController.cs +++ b/src/Server/Controllers/EntityController.cs @@ -31,10 +31,14 @@ public class EntityController : ControllerBase try { searchdomain_ = _domainManager.GetSearchdomain(searchdomain); - } catch (Exception) + } catch (SearchdomainNotFoundException) { - _logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]); // TODO DRY violation; perhaps move this logging to the SearchdomainManager? - return Ok(new EntityQueryResults() {Results = []}); + _logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]); + return Ok(new EntityQueryResults() {Results = [], Success = false, Message = "Searchdomain not found" }); + } catch (Exception ex) + { + _logger.LogError("Unable to retrieve the searchdomain {searchdomain} - {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]); + return Ok(new EntityQueryResults() {Results = [], Success = false, Message = "Unable to retrieve the searchdomain - it likely exists, but some other error happened." }); } var results = searchdomain_.Search(query); List queryResults = [.. results.Select(r => new EntityQueryResult @@ -42,7 +46,7 @@ public class EntityController : ControllerBase Name = r.Item2, Value = r.Item1 })]; - return Ok(new EntityQueryResults(){Results = queryResults}); + return Ok(new EntityQueryResults(){Results = queryResults, Success = true }); } [HttpPost("Index")] @@ -94,10 +98,14 @@ public class EntityController : ControllerBase try { searchdomain_ = _domainManager.GetSearchdomain(searchdomain); - } catch (Exception) + } catch (SearchdomainNotFoundException) { _logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]); - return Ok(new EntityListResults() { Results = [], Success = false }); + return Ok(new EntityQueryResults() {Results = [], Success = false, Message = "Searchdomain not found" }); + } catch (Exception ex) + { + _logger.LogError("Unable to retrieve the searchdomain {searchdomain} - {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]); + return Ok(new EntityQueryResults() {Results = [], Success = false, Message = "Unable to retrieve the searchdomain - it likely exists, but some other error happened." }); } EntityListResults entityListResults = new() {Results = [], Success = true}; foreach (Entity entity in searchdomain_.entityCache) @@ -142,7 +150,7 @@ public class EntityController : ControllerBase if (entity_ is null) { _logger.LogError("Unable to delete the entity {entityName} in {searchdomain} - it was not found under the specified name", [entityName, searchdomain]); - return Ok(new EntityDeleteResults() {Success = false}); + return Ok(new EntityDeleteResults() {Success = false, Message = "Entity not found"}); } _databaseHelper.RemoveEntity([], _domainManager.helper, entityName, searchdomain); return Ok(new EntityDeleteResults() {Success = true}); diff --git a/src/Shared/Models/EntityResults.cs b/src/Shared/Models/EntityResults.cs index 7a39a14..025a2e7 100644 --- a/src/Shared/Models/EntityResults.cs +++ b/src/Shared/Models/EntityResults.cs @@ -7,6 +7,10 @@ public class EntityQueryResults { [JsonPropertyName("Results")] public required List Results { get; set; } + [JsonPropertyName("Success")] + public required bool Success { get; set; } + [JsonPropertyName("Message")] + public string? Message { get; set; } } public class EntityQueryResult @@ -75,5 +79,7 @@ public class EntityDeleteResults { [JsonPropertyName("Success")] public required bool Success { get; set; } + [JsonPropertyName("Message")] + public string? Message { get; set; } }