Fixes a few crashes and search functionality. (#307)

* Fixes a few crashes and search functionality.

* Use PostError
This commit is contained in:
Danil Yarantsev 2021-11-22 02:40:04 +03:00 committed by GitHub
commit 40d7b1cf02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -882,6 +882,11 @@ routes:
where t.id = ? and isDeleted = 0 and category = c.id;"""
let threadRow = getRow(db, threadsQuery, id)
if threadRow[0].len == 0:
let err = PostError(
message: "Specified thread does not exist"
)
resp Http404, $(%err), "application/json"
let thread = selectThread(threadRow, selectThreadAuthor(id))
let postsQuery =
@ -927,9 +932,14 @@ routes:
get "/specific_posts.json":
createTFD()
var
var ids: JsonNode
try:
ids = parseJson(@"ids")
except JsonParsingError:
let err = PostError(
message: "Invalid JSON in the `ids` parameter"
)
resp Http400, $(%err), "application/json"
cond ids.kind == JArray
let intIDs = ids.elems.map(x => x.getInt())
let postsQuery = sql("""

View file

@ -7,6 +7,7 @@ SELECT
post_id,
post_content,
cdate,
person.id,
person.name AS author,
person.email AS email,
strftime('%s', person.lastOnline) AS lastOnline,