Improve error handling
This commit is contained in:
parent
d6190b024d
commit
0b4975e74b
|
|
@ -137,13 +137,13 @@ public sealed class HttpServer {
|
||||||
private string NormalizeUrlPath(string url) => '/' + url.TrimStart('/');
|
private string NormalizeUrlPath(string url) => '/' + url.TrimStart('/');
|
||||||
|
|
||||||
private async Task ProcessRequestAsync(HttpListenerContext ctx) {
|
private async Task ProcessRequestAsync(HttpListenerContext ctx) {
|
||||||
|
using RequestContext rc = new RequestContext(ctx);
|
||||||
try {
|
try {
|
||||||
var decUri = WebUtility.UrlDecode(ctx.Request.RawUrl)!; // TODO add path escape countermeasures+unittests
|
var decUri = WebUtility.UrlDecode(ctx.Request.RawUrl)!; // TODO add path escape countermeasures+unittests
|
||||||
var splitted = NormalizeUrlPath(decUri).Split('?', 2, StringSplitOptions.None);
|
var splitted = NormalizeUrlPath(decUri).Split('?', 2, StringSplitOptions.None);
|
||||||
var path = WebUtility.UrlDecode(splitted.First());
|
var path = WebUtility.UrlDecode(splitted.First());
|
||||||
|
|
||||||
|
|
||||||
using var rc = new RequestContext(ctx);
|
|
||||||
if (simpleEndpointMethodInfos.TryGetValue((decUri, ctx.Request.HttpMethod.ToUpperInvariant()), out var endpointInvocationInfo)) {
|
if (simpleEndpointMethodInfos.TryGetValue((decUri, ctx.Request.HttpMethod.ToUpperInvariant()), out var endpointInvocationInfo)) {
|
||||||
var mi = endpointInvocationInfo.methodInfo;
|
var mi = endpointInvocationInfo.methodInfo;
|
||||||
var qparams = endpointInvocationInfo.queryParameters;
|
var qparams = endpointInvocationInfo.queryParameters;
|
||||||
|
|
@ -198,6 +198,7 @@ public sealed class HttpServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
await HandleDefaultErrorPageAsync(rc, 500);
|
||||||
logger.Fatal($"Caught otherwise uncaught exception while ProcessingRequest:\n{ex}");
|
logger.Fatal($"Caught otherwise uncaught exception while ProcessingRequest:\n{ex}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user