From 508510962a4c271c9b13d9cff99aaee4541af447 Mon Sep 17 00:00:00 2001 From: limited_dev Date: Tue, 13 Jun 2023 07:42:48 +0200 Subject: [PATCH] fix: Page no longer Errors when accessing a nonexistent thread Signed-off-by: limited_dev --- .../Pages/Basic/ThreadPage.razor | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ImageBoardServerApp/Pages/Basic/ThreadPage.razor b/ImageBoardServerApp/Pages/Basic/ThreadPage.razor index 8f860ac..f5e7d69 100644 --- a/ImageBoardServerApp/Pages/Basic/ThreadPage.razor +++ b/ImageBoardServerApp/Pages/Basic/ThreadPage.razor @@ -19,30 +19,30 @@ @code { + [Parameter] [Required] public string boardName { get; set; } - + [Parameter] [Required] public string threadId { get; set; } - + private PostData post; protected override async Task OnInitializedAsync() { - try - { - post = await PostsRepository.getPostByIdAsync(int.Parse(threadId)); - } - catch (FormatException fe) - { + if (!int.TryParse(threadId, out _)) NavigationManager.NavigateTo("/notfound"); - return; - } - if(post.Board != boardName) + post = await PostsRepository.getPostByIdAsync(int.Parse(threadId)); + + if (post == null) NavigationManager.NavigateTo("/notfound"); - if(post == null) + + if (post.Board != boardName) + NavigationManager.NavigateTo("/notfound"); + if (post == null) NavigationManager.NavigateTo("/notfound"); } + } \ No newline at end of file