Skip to content

Commit 0a3f6b4

Browse files
committed
Improve consistency
1 parent db1a19c commit 0a3f6b4

File tree

5 files changed

+338
-37
lines changed

5 files changed

+338
-37
lines changed

src/Initium/Exceptions/ApiException.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,22 @@ public class ApiException : Exception
1818
/// <param name="statusCode">The HTTP status code associated with this exception. Defaults to <see cref="HttpStatusCode.InternalServerError"/>.</param>
1919
/// <param name="message">The message describing the error. Defaults to a generic error message.</param>
2020
/// <param name="innerException">The inner exception that caused the current exception. Optional.</param>
21-
public ApiException(HttpStatusCode statusCode = HttpStatusCode.InternalServerError, string? message = null, Exception? innerException = null)
21+
public ApiException(HttpStatusCode? statusCode = null, string? message = null, Exception? innerException = null)
2222
: base(message, innerException)
2323
{
2424
CustomMessage = message;
25-
StatusCode = statusCode;
25+
StatusCode = statusCode ?? HttpStatusCode.InternalServerError;
26+
}
27+
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="ApiException"/> class with a specified message and optional inner exception, defaulting the status code to InternalServerError.
30+
/// </summary>
31+
/// <param name="message">The message describing the error.</param>
32+
/// <param name="innerException">The inner exception that caused the current exception. Optional.</param>
33+
public ApiException(string? message, Exception? innerException = null)
34+
: base(message, innerException)
35+
{
36+
CustomMessage = message;
37+
StatusCode = HttpStatusCode.InternalServerError;
2638
}
2739
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.AspNetCore.Identity;
2+
3+
namespace Initium.Extensions;
4+
5+
public static class IdentityResultExtensions
6+
{
7+
/// <summary>
8+
/// Gets a value indicating whether the identity operation has failed.
9+
/// Equivalent to <c>!result.Succeeded</c>.
10+
/// </summary>
11+
/// <param name="result">The identity result.</param>
12+
/// <returns><c>true</c> if the operation failed; otherwise, <c>false</c>.</returns>
13+
public static bool HasFailed(this IdentityResult result) => !result.Succeeded;
14+
}

src/Initium/Initium.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
<ItemGroup>
3030
<PackageReference Include="FluentValidation" Version="12.0.0" />
31-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0"/>
32-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.3.0"/>
3331
<PackageReference Include="Tapper.Attributes" Version="1.13.1" />
3432
<PackageReference Include="YamlDotNet" Version="16.3.0" />
3533
</ItemGroup>

src/Initium/Results/BaseResult.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net;
2+
using Initium.Response;
23

34
namespace Initium.Results;
45

@@ -26,6 +27,12 @@ public abstract class BaseResult
2627
/// </summary>
2728
public HttpStatusCode? StatusCode { get; set; }
2829

30+
/// <summary>
31+
/// Gets or sets the collection of structured errors associated with the result.
32+
/// Each <see cref="ApiError"/> provides details such as an error code and description.
33+
/// </summary>
34+
public IEnumerable<ApiError>? Errors { get; set; }
35+
2936
/// <summary>
3037
/// Gets or sets metadata associated with the result, which can be mapped to HTTP headers.
3138
/// </summary>

0 commit comments

Comments
 (0)