Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: .NET Build

on: [push, pull_request]
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Applications.Abstractions/Results/ResultMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class ResultMessage
{
public ResultMessage(ResultMessageType type, string message, string field = null, string code = null)
public ResultMessage(ResultMessageType type, string message, string? field= null, string? code = null)
{
Type = type;
Message = message;
Expand All @@ -12,9 +12,9 @@ public ResultMessage(ResultMessageType type, string message, string field = null

public string Message { get; set; }

public string Field { get; set; }
public string? Field { get; set; }

public string Code { get; set; }
public string? Code { get; set; }

public ResultMessageType Type { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public static void AppendInfo(this Result result, string message)
result.Messages.Add(new ResultMessage(ResultMessageType.Info, message));
}

public static void AppendError(this Result result, string message, string field, string code)
public static void AppendError(this Result result, string message, string? field, string? code)
{
result.Messages.Add(new ResultMessage(ResultMessageType.Error, message, field, code));
result.Messages.Add(new ResultMessage(ResultMessageType.Error, message, code:code , field: field));
}

public static void AppendError(this Result result, string message, string field)
public static void AppendError(this Result result, string message, string? field)
{
result.AppendError(message, field, null);
result.AppendError(message, field: field, null);
}

public static void AppendError(this Result result, string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ private TResponse CreateResultWithError(Type type, Exception ex)
result.SetStatusAsUnauthorized();
result.AppendError(ex.Message);
break;
case NotFoundBusinessException notFoundEx:
result.Status = ResultStatus.NotFound;
result.AppendError(notFoundEx.GetMessage(), null, notFoundEx.GetCode());
break;
case BusinessException businessException:
result.Status = ResultStatus.ValidationError;
var code = businessException.GetCode();
Expand Down
9 changes: 9 additions & 0 deletions src/Core/Domain.Abstractions/NotFoundBusinessException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Honamic.Framework.Domain;

public class NotFoundBusinessException : BusinessException
{
public NotFoundBusinessException(string? message = null, string? code = null)
: base(message ?? "Item not found.", code)
{
}
}
1 change: 1 addition & 0 deletions src/Facade/Default/Honamic.Framework.Facade.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Core\Domain.Abstractions\Honamic.Framework.Domain.Abstractions.csproj" />
<ProjectReference Include="..\..\Utilities\Default\Honamic.Framework.Utilities.csproj" />
<ProjectReference Include="..\Abstractions\Honamic.Framework.Facade.Abstractions.csproj" />
</ItemGroup>
Expand Down
21 changes: 15 additions & 6 deletions src/Facade/Default/Interceptors/ExceptionHandlingInterceptor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Castle.DynamicProxy;
using Honamic.Framework.Applications.Exceptions;
using Honamic.Framework.Applications.Results;
using Honamic.Framework.Domain;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
using System.Reflection;
Expand Down Expand Up @@ -36,7 +37,7 @@ public void Intercept(IInvocation invocation)
{
if (invocation.Proxy is IBaseFacade baseFacade)
{
baseFacade.Logger.LogError(ex, "Unhandled exception");
baseFacade.Logger.LogError(ex, "Unhandled exception");
}

var result = GetNewResult(invocation, ex);
Expand Down Expand Up @@ -111,16 +112,24 @@ public void Intercept(IInvocation invocation)
switch (ex)
{
case UnauthenticatedException:
rawResult?.SetStatusAsUnauthenticated();
rawResult?.AppendError(ex.Message, "Exception");
rawResult.SetStatusAsUnauthenticated(ex.Message);
break;
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider ensuring that the null handling of 'rawResult' is consistent across all exception cases; some cases use the null-conditional operator while others do not, so validating the non-null assumption here might help avoid potential issues.

Copilot uses AI. Check for mistakes.
case UnauthorizedException:
rawResult?.SetStatusAsUnauthorized();
rawResult?.AppendError(ex.Message, "Exception");
rawResult.SetStatusAsUnauthorized(ex.Message);
break;
case NotFoundBusinessException notFoundEx:
rawResult.SetStatusAsNotFound();
rawResult.AppendError(notFoundEx.GetMessage(), null, notFoundEx.GetCode());
break;
case BusinessException businessException:
rawResult.Status = ResultStatus.ValidationError;
var code = businessException.GetCode();
var message = businessException.GetMessage();
rawResult.AppendError(message, null, code);
break;
default:
rawResult?.SetStatusAsUnhandledExceptionWithSorryError();
rawResult?.AppendError(ex.ToString(), "Exception");
rawResult?.AppendError(ex.Message, "Exception");
Comment on lines 131 to +132
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the inconsistent use of the null-conditional operator on 'rawResult'; aligning its usage across all cases will improve code clarity and reduce ambiguity in error handling.

Copilot uses AI. Check for mistakes.
break;
}

Expand Down
Loading