better error handling for this
This commit is contained in:
parent
be1dd411ee
commit
ce0fb7983a
|
@ -199,48 +199,50 @@ routes:
|
||||||
fail()
|
fail()
|
||||||
|
|
||||||
get "/@kind/@id":
|
get "/@kind/@id":
|
||||||
var
|
|
||||||
title: string = ""
|
|
||||||
ctx: Context
|
|
||||||
rows: seq[Row]
|
|
||||||
qid: int = 0
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
qid = (@"id").parseInt
|
var
|
||||||
except:
|
title: string = ""
|
||||||
qid = (@"id").decodeURLSimple()
|
ctx: Context
|
||||||
redirect "/" & @"kind" & "/" & $qid
|
rows: seq[Row]
|
||||||
|
qid: int = 0
|
||||||
|
|
||||||
case @"kind":
|
try:
|
||||||
of "browse":
|
qid = (@"id").parseInt
|
||||||
rows = db.getAllRows(sql"SELECT * FROM quotes where deleted=0 ORDER BY time desc LIMIT 20 OFFSET ?", (qid * 20))
|
except:
|
||||||
|
qid = (@"id").decodeURLSimple()
|
||||||
|
redirect "/" & @"kind" & "/" & $qid
|
||||||
|
|
||||||
title = "page " & @"id"
|
case @"kind":
|
||||||
of "quotes":
|
of "browse":
|
||||||
rows = db.getAllRows(sql"SELECT * FROM quotes WHERE id = ?", qid)
|
rows = db.getAllRows(sql"SELECT * FROM quotes where deleted=0 ORDER BY time desc LIMIT 20 OFFSET ?", (qid * 20))
|
||||||
|
|
||||||
title = "#" & $qid & " by " & rows[0][2]
|
title = "page " & @"id"
|
||||||
else:
|
of "quotes":
|
||||||
if (@"kind").startsWith "hashtag-":
|
rows = db.getAllRows(sql"SELECT * FROM quotes WHERE id = ?", qid)
|
||||||
let channel = (@"kind").replace("hashtag-", "#")
|
|
||||||
|
|
||||||
rows = db.getAllRows(sql"SELECT * FROM quotes WHERE channel=?, deleted=0 ORDER BY time desc LIMIT 20 OFFSET ?", channel, qid * 20)
|
title = "#" & $qid & " by " & rows[0][2]
|
||||||
|
|
||||||
title = channel & " page " & @"id"
|
|
||||||
else:
|
else:
|
||||||
halt Http404, "not found"
|
if (@"kind").startsWith "hashtag-":
|
||||||
|
let channel = (@"kind").replace("hashtag-", "#")
|
||||||
|
|
||||||
ctx = newContext()
|
rows = db.getAllRows(sql"SELECT * FROM quotes WHERE channel=?, deleted=0 ORDER BY time desc LIMIT 20 OFFSET ?", channel, qid * 20)
|
||||||
var quoteSeq = newSeq[Context]()
|
|
||||||
|
|
||||||
for row in items(rows):
|
title = channel & " page " & @"id"
|
||||||
var c = newContext()
|
else:
|
||||||
c.contextQuote row[0].parseInt(), row
|
halt Http404, "not found"
|
||||||
quoteSeq.add c
|
|
||||||
|
|
||||||
ctx["quotes"] = quoteSeq
|
ctx = newContext()
|
||||||
ctx.pagination(qid, @"kind")
|
var quoteSeq = newSeq[Context]()
|
||||||
|
|
||||||
renderMustache(title, browseTemplate, ctx)
|
for row in items(rows):
|
||||||
|
var c = newContext()
|
||||||
|
c.contextQuote row[0].parseInt(), row
|
||||||
|
quoteSeq.add c
|
||||||
|
|
||||||
|
ctx["quotes"] = quoteSeq
|
||||||
|
ctx.pagination(qid, @"kind")
|
||||||
|
|
||||||
|
renderMustache(title, browseTemplate, ctx)
|
||||||
|
except: fail()
|
||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
Loading…
Reference in New Issue