blob: acc186bb3716e5ab50ab76a1981d2e4f0ea1bbbc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
using System.Text.Json;
using System.Text.Json.Nodes;
using Microsoft.AspNetCore.Mvc;
namespace ReferenceClientProxyImplementation.Controllers;
[Controller]
[Route("/")]
public class ErrorReportingProxy : Controller {
[HttpPost("/error-reporting-proxy/web")]
public async Task<ActionResult> HandleErrorReport() {
// read body as string
var body = await new StreamReader(Request.Body).ReadToEndAsync();
var lines = body.Split('\n');
var data = new JsonObject() {
["eventInfo"] = JsonSerializer.Deserialize<JsonObject>(lines[0]),
["typeInfo"] = JsonSerializer.Deserialize<JsonObject>(lines[1]),
["stackTrace"] = JsonSerializer.Deserialize<JsonObject>(lines[2]),
};
if (lines.Length > 3)
for (var i = 3; i < lines.Length; i++) {
data[$"unk_line_{i}"] = JsonSerializer.Deserialize<JsonValue>(lines[i]);
}
if (!System.IO.Directory.Exists("error_reports"))
System.IO.Directory.CreateDirectory("error_reports");
await System.IO.File.WriteAllTextAsync($"error_reports/web_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}.json", data.ToJsonString(new JsonSerializerOptions {
WriteIndented = true
}));
return NoContent();
}
}
|