Skip to content

Commit 36a5b55

Browse files
committed
[Milky] Fix api failed no status field
1 parent bc0d204 commit 36a5b55

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Lagrange.Milky/Implementation/Api/ApiFailedResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Lagrange.Milky.Implementation.Api;
55
public class ApiFailedResult
66
{
77
[JsonPropertyName("status")]
8-
public static string Status => "failed";
8+
public string Status => "failed";
99

1010
[JsonPropertyName("retcode")]
1111
public required long Retcode { get; init; }

Lagrange.Milky/Implementation/Communication/MilkyHttpApiService.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ private async Task HandleHttpContextAsync(HttpListenerContext context, Cancellat
8383
object? parameter;
8484
try
8585
{
86+
// TODO: _logger.LogReceive(identifier, request.RemoteEndPoint, );
87+
request.InputStream.Seek(0, SeekOrigin.Begin);
8688
parameter = await MilkyJsonUtility.DeserializeAsync(
8789
handler.ParameterType,
8890
request.InputStream,
@@ -220,10 +222,17 @@ public static partial class MilkyApiServiceLoggerExtension
220222
[LoggerMessage(EventId = 1, Level = LogLevel.Information, Message = "{identifier} {remote} -->> {method} {path}")]
221223
public static partial void LogHttpContext(this ILogger<MilkyHttpApiService> logger, Guid identifier, IPEndPoint remote, string method, string? path);
222224

223-
[LoggerMessage(EventId = 2, Message = "{identifier} {remote} <<-- {status}")]
225+
[LoggerMessage(EventId = 2, Level = LogLevel.Information, Message = "{identifier} {remote} -->> {body}", SkipEnabledCheck = true)]
226+
private static partial void LogReceive(this ILogger<MilkyHttpApiService> logger, Guid identifier, IPEndPoint remote, string body);
227+
public static void LogReceive(this ILogger<MilkyHttpApiService> logger, Guid identifier, IPEndPoint remote, Span<byte> bytes)
228+
{
229+
if (logger.IsEnabled(LogLevel.Information)) logger.LogReceive(identifier, remote, Encoding.UTF8.GetString(bytes));
230+
}
231+
232+
[LoggerMessage(EventId = 3, Message = "{identifier} {remote} <<-- {status}")]
224233
public static partial void LogSend(this ILogger<MilkyHttpApiService> logger, LogLevel level, Guid identifier, IPEndPoint remote, HttpStatusCode status, Exception? e);
225234

226-
[LoggerMessage(EventId = 3, Message = "{identifier} {remote} <<-- {body}", SkipEnabledCheck = true)]
235+
[LoggerMessage(EventId = 4, Message = "{identifier} {remote} <<-- {body}", SkipEnabledCheck = true)]
227236
private static partial void LogSend(this ILogger<MilkyHttpApiService> logger, LogLevel level, Guid identifier, IPEndPoint remote, string body, Exception? e);
228237
public static void LogSend(this ILogger<MilkyHttpApiService> logger, LogLevel level, Guid identifier, IPEndPoint remote, byte[] body, Exception? e)
229238
{

0 commit comments

Comments
 (0)