From c12c1ab7d2241b4411775499bbf42c6507383ad3 Mon Sep 17 00:00:00 2001 From: Meik Date: Wed, 1 Jul 2026 14:23:28 +0200 Subject: [PATCH] fix: avoid null api responses --- F4SDM42WebApi/F4SD - M42WebApi.csproj | 2 +- F4SDM42WebApi/F4SDM42WebApiController.cs | 37 ++++++++++++------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/F4SDM42WebApi/F4SD - M42WebApi.csproj b/F4SDM42WebApi/F4SD - M42WebApi.csproj index 8dc12fb..2375f25 100644 --- a/F4SDM42WebApi/F4SD - M42WebApi.csproj +++ b/F4SDM42WebApi/F4SD - M42WebApi.csproj @@ -13,7 +13,7 @@ false 6673a25d-33d6-4072-91d9-abed4be1a966 C4ITF4SD*.* - 1.4.0.38 + 1.4.0.39 true diff --git a/F4SDM42WebApi/F4SDM42WebApiController.cs b/F4SDM42WebApi/F4SDM42WebApiController.cs index d0d4f8f..31cc3d6 100644 --- a/F4SDM42WebApi/F4SDM42WebApiController.cs +++ b/F4SDM42WebApi/F4SDM42WebApiController.cs @@ -98,12 +98,13 @@ namespace C4IT.F4SD public async Task getDirectLinkCreateTicket(string sid = "", string assetname = "") { await Task.Delay(0); - return await _f4stHelperService.getDirectLinkCreateTicket(sid, assetname); + return await _f4stHelperService.getDirectLinkCreateTicket(sid, assetname) + ?? new F4SDHelperService.DirectLink(); } [Route("getDirectLinkF4SD"), HttpGet] public async Task getDirectLinkF4SD(Guid EOID, string Type) { - return await _f4stHelperService.getDirectLinkF4SD(EOID, Type); + return await _f4stHelperService.getDirectLinkF4SD(EOID, Type) ?? string.Empty; } [Route("getTicketList"), HttpGet] @@ -130,16 +131,16 @@ namespace C4IT.F4SD public async Task getTicketDetails(Guid objectId) { var tickets = await _f4stHelperService.getTicketDetails(new List() { objectId }); - if (tickets.Count > 0) + if (tickets?.Count > 0) return tickets[0]; - else - return null; + + return new cF4SDTicket { TicketObjectId = objectId }; } [Route("getTicketHistory"), HttpGet] public async Task> getTicketHistory(Guid objectId) { - return await _f4stHelperService.GetJournalEntries(objectId); + return await _f4stHelperService.GetJournalEntries(objectId) ?? new List(); } [Route("getTicketOverviewCounts"), HttpGet] @@ -158,7 +159,8 @@ namespace C4IT.F4SD .ToList(); var decodedQueues = ParseQueues(queues); - return await _f4stHelperService.getTicketOverviewCounts(sid, scope, parsedKeys, queueoption, decodedQueues); + return await _f4stHelperService.getTicketOverviewCounts(sid, scope, parsedKeys, queueoption, decodedQueues) + ?? new F4SDHelperService.TicketOverviewCountsResult(); } [Route("getTicketOverviewCountsByRoles"), HttpPost] @@ -182,7 +184,7 @@ namespace C4IT.F4SD parsedKeys, request?.QueueOption ?? 0, decodedQueues - ); + ) ?? new F4SDHelperService.TicketOverviewCountsByRoleResult(); } [Route("getTicketOverviewRelations"), HttpGet] @@ -196,7 +198,8 @@ namespace C4IT.F4SD ) { var decodedQueues = ParseQueues(queues); - return await _f4stHelperService.getTicketOverviewRelations(sid, scope, key, count, queueoption, decodedQueues); + return await _f4stHelperService.getTicketOverviewRelations(sid, scope, key, count, queueoption, decodedQueues) + ?? new List(); } /* [Route("updateActivitySolution/{objectId}"), HttpPost] @@ -244,7 +247,7 @@ namespace C4IT.F4SD throw new UnauthorizedAccessException("Cannot determine the interactive Matrix42 user."); var filter = AsqlHelper.BuildInCondition("ID", new Guid[] { userId }); - return await _f4stHelperService.UserPermissionsInfo(filter); + return await _f4stHelperService.UserPermissionsInfo(filter) ?? new UserPermissionsInfo(); } [HttpGet] [Route("getRoleMemberships")] @@ -267,12 +270,10 @@ namespace C4IT.F4SD if (!string.IsNullOrEmpty(filter)) { - return await _f4stHelperService.UserPermissionsInfo(filter); - } - else - { - return null; + return await _f4stHelperService.UserPermissionsInfo(filter) ?? new UserPermissionsInfo(); } + + return new UserPermissionsInfo(); } public class TicketOverviewCountsByRolesRequest @@ -414,7 +415,7 @@ namespace C4IT.F4SD catch (Exception E) { LogException(E); - return null; + return string.Empty; } finally { @@ -486,7 +487,7 @@ namespace C4IT.F4SD catch (Exception E) { LogException(E); - return null; + return Enumerable.Empty(); } } @@ -501,7 +502,7 @@ namespace C4IT.F4SD [OperationType(OperationType.GetObject)] public cM42LogEntry GetClass(int id) { - return _f4stHelperService.privGetLog2(id); + return _f4stHelperService.privGetLog2(id) ?? new cM42LogEntry { LineNumber = id }; } private static IEnumerable ApplyLogFilter(IEnumerable entries, ODataQueryOptions queryOptions)