diff --git a/src/nitter.nim b/src/nitter.nim index 9e3e452..515113d 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -38,6 +38,9 @@ routes: get "/help": redirect("/about") + error Http404: + resp showError("Page not found", cfg.title) + extend unsupported, "" extend preferences, "" extend rss, "" diff --git a/src/routes/list.nim b/src/routes/list.nim index 312e56c..9206504 100644 --- a/src/routes/list.nim +++ b/src/routes/list.nim @@ -8,7 +8,7 @@ import ../views/[general, timeline, list] template respList*(list, timeline: typed) = if list.minId.len == 0: - resp Http404, showError("List \"" & @"list" & "\" not found", cfg.title) + halt Http404, showError("List \"" & @"list" & "\" not found", cfg.title) let html = renderList(timeline, list.query, @"name", @"list") let rss = "/$1/lists/$2/rss" % [@"name", @"list"] resp renderMain(html, request, cfg.title, rss=rss) diff --git a/src/routes/media.nim b/src/routes/media.nim index f187853..0dc93dd 100644 --- a/src/routes/media.nim +++ b/src/routes/media.nim @@ -33,7 +33,7 @@ proc createMediaRouter*(cfg: Config) = discard if not existsFile(filename): - resp Http404 + halt Http404 let file = openAsync(filename) let buf = await readAll(file) @@ -58,7 +58,7 @@ proc createMediaRouter*(cfg: Config) = discard if content.len == 0: - resp Http404 + halt Http404 resp content, mimetype(url) diff --git a/src/routes/rss.nim b/src/routes/rss.nim index 30dcd28..80582ab 100644 --- a/src/routes/rss.nim +++ b/src/routes/rss.nim @@ -15,7 +15,7 @@ proc showRss*(name: string; query: Query): Future[string] {.async.} = template respRss*(rss: typed) = if rss.len == 0: - resp Http404, showError("User \"" & @"name" & "\" not found", cfg.title) + halt Http404, showError("User \"" & @"name" & "\" not found", cfg.title) resp rss, "application/rss+xml;charset=utf-8" proc createRssRouter*(cfg: Config) = diff --git a/src/routes/search.nim b/src/routes/search.nim index 4586b9c..706804a 100644 --- a/src/routes/search.nim +++ b/src/routes/search.nim @@ -29,7 +29,7 @@ proc createSearchRouter*(cfg: Config) = resp renderMain(renderTweetSearch(tweets, prefs, getPath()), request, cfg.title, rss=rss) else: - resp Http404, showError("Invalid search.", cfg.title) + halt Http404, showError("Invalid search", cfg.title) get "/hashtag/@hash": redirect("/search?q=" & encodeUrl("#" & @"hash")) diff --git a/src/routes/status.nim b/src/routes/status.nim index 22acc92..8329b29 100644 --- a/src/routes/status.nim +++ b/src/routes/status.nim @@ -19,10 +19,10 @@ proc createStatusRouter*(cfg: Config) = let conversation = await getTweet(@"name", @"id", @"after", getAgent()) if conversation == nil or conversation.tweet.id.len == 0: + var error = "Tweet not found" if conversation != nil and conversation.tweet.tombstone.len > 0: - resp Http404, showError(conversation.tweet.tombstone, cfg.title) - else: - resp Http404, showError("Tweet not found", cfg.title) + error = conversation.tweet.tombstone + halt Http404, showError(error, cfg.title) let title = pageTitle(conversation.tweet.profile) diff --git a/src/routes/timeline.nim b/src/routes/timeline.nim index 2de73a1..cc62d3b 100644 --- a/src/routes/timeline.nim +++ b/src/routes/timeline.nim @@ -72,7 +72,7 @@ proc showTimeline*(request: Request; query: Query; title, rss: string): Future[s template respTimeline*(timeline: typed) = if timeline.len == 0: - resp Http404, showError("User \"" & @"name" & "\" not found", cfg.title) + halt Http404, showError("User \"" & @"name" & "\" not found", cfg.title) resp timeline proc createTimelineRouter*(cfg: Config) =