minor fixes

This commit is contained in:
Pilzinsel64
2024-08-16 10:01:57 +02:00
parent a58bd055b5
commit f509c53836
2 changed files with 7 additions and 3 deletions

View File

@@ -23,4 +23,6 @@ public record class ApiResult(
public static ApiResult ServiceUnavailable() => new(HttpStatusCode.ServiceUnavailable); public static ApiResult ServiceUnavailable() => new(HttpStatusCode.ServiceUnavailable);
public static ApiResult UnavailableForLegalReasons() => new(HttpStatusCode.UnavailableForLegalReasons); public static ApiResult UnavailableForLegalReasons() => new(HttpStatusCode.UnavailableForLegalReasons);
public static ApiResult InternalServerError() => new(HttpStatusCode.InternalServerError);
} }

View File

@@ -159,6 +159,8 @@ public class ApiServer(string apiUrl) : IApiServer
isAuthenticated = CheckAuthentication(authKeyDecoded); isAuthenticated = CheckAuthentication(authKeyDecoded);
else else
authKeyDecoded = null!; authKeyDecoded = null!;
if (attribute.RequiesAuth && !isAuthenticated)
return new(ApiResult.Unauthorized(), null);
// Get required infos // Get required infos
Log.Debug("Find other infos"); Log.Debug("Find other infos");
@@ -177,7 +179,7 @@ public class ApiServer(string apiUrl) : IApiServer
Log.Debug("Invoke handler"); Log.Debug("Invoke handler");
var parameters = BuildParameters(handler, () => message, () => new(message, isAuthenticated, authKeyDecoded)); var parameters = BuildParameters(handler, () => message, () => new(message, isAuthenticated, authKeyDecoded));
if (handler.DynamicInvoke(parameters) is not ApiResult result) if (handler.DynamicInvoke(parameters) is not ApiResult result)
return null; return new(ApiResult.InternalServerError(), null);
// Return result without message // Return result without message
Log.Debug("Check message"); Log.Debug("Check message");
@@ -187,10 +189,10 @@ public class ApiServer(string apiUrl) : IApiServer
// Serializer // Serializer
Log.Debug("Serialize message"); Log.Debug("Serialize message");
if (serializer.Serialize(result.Message) is not string resultStr) if (serializer.Serialize(result.Message) is not string resultStr)
return null; return new(ApiResult.InternalServerError(), null);
// Return result with message // Return result with message
Log.Debug("Finish result"); Log.Debug("Complete result");
return new(result, resultStr); return new(result, resultStr);
} }