api: bad request on fail

This commit is contained in:
Pilzinsel64
2025-10-22 07:13:19 +02:00
parent b27fe9362a
commit ef1b6bad2e

View File

@@ -349,7 +349,7 @@ public class ApiServer : IApiServer
}
catch (MissingDataManagerException mdmex)
{
Log.Error("DataManager is not supported by this server instnace!", mdmex);
Log.Error("DataManager is not supported by this server instance!", mdmex);
if (DebugMode) throw;
}
catch (Exception ex)
@@ -387,9 +387,11 @@ public class ApiServer : IApiServer
{
Log.Debug("Start handling request");
void close()
void close(bool badRequest)
{
Log.Debug("End handling request");
if (badRequest)
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
context.Response.OutputStream.Close();
}
@@ -400,7 +402,7 @@ public class ApiServer : IApiServer
if (string.IsNullOrWhiteSpace(path))
{
Log.Warn("Request has no path");
close();
close(true);
return;
}
@@ -409,7 +411,7 @@ public class ApiServer : IApiServer
if (!TryGetHandler(path, query, context.Request.HttpMethod, out var handler))
{
Log.Warn("Request handler couldn't be found");
close();
close(true);
return;
}
@@ -433,13 +435,13 @@ public class ApiServer : IApiServer
catch (OutOfMemoryException)
{
Log.Error("Error reading remote data due to missing memory");
close();
close(true);
return;
}
catch (Exception ex)
{
Log.Error("Error reading remote data", ex);
close();
close(true);
return;
}
}
@@ -451,7 +453,7 @@ public class ApiServer : IApiServer
if (HandleMessage(context, path, query, handler, contentJson, authKey) is not PrivateApiResult result)
{
Log.Warn("Request couldn't be handled");
close();
close(true);
return;
}
@@ -482,7 +484,8 @@ public class ApiServer : IApiServer
}
Log.Debug("Finish response");
close();
close(false);
return;
}
protected virtual PrivateApiResult? HandleMessage(HttpListenerContext context, string url, string? query, PrivateMessageHandler handler, string? json, string? authKey)