Use custom 404 page, halt on 404 instead of resp
This commit is contained in:
parent
8fcdfa744a
commit
ebb89edef6
7 changed files with 12 additions and 9 deletions
|
@ -38,6 +38,9 @@ routes:
|
|||
get "/help":
|
||||
redirect("/about")
|
||||
|
||||
error Http404:
|
||||
resp showError("Page not found", cfg.title)
|
||||
|
||||
extend unsupported, ""
|
||||
extend preferences, ""
|
||||
extend rss, ""
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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) =
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) =
|
||||
|
|
Loading…
Reference in a new issue