fix: show 404 page if /api/v2/meta/page/{page} can't find a file

This commit is contained in:
sam 2025-02-23 21:42:01 +01:00
parent 0c6e3bf38f
commit c8e4078b35
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
6 changed files with 17 additions and 9 deletions

View file

@ -58,8 +58,15 @@ public partial class MetaController(Config config) : ApiControllerBase
}
string path = Path.Join(Directory.GetCurrentDirectory(), "static-pages", $"{page}.md");
string text = await System.IO.File.ReadAllTextAsync(path, ct);
return Ok(text);
try
{
string text = await System.IO.File.ReadAllTextAsync(path, ct);
return Ok(text);
}
catch (FileNotFoundException)
{
throw new ApiError.NotFound("Page not found", code: ErrorCode.PageNotFound);
}
}
[HttpGet("/api/v2/coffee")]