Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/jsons/status.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ proc createJsonApiStatusRouter*(cfg: Config) =
var error = "Tweet not found"
if conv != nil and conv.tweet != nil and conv.tweet.tombstone.len > 0:
error = conv.tweet.tombstone
respJsonError error
respJsonError(error, "not_found", Http404)

respJsonSuccess formatConversationAsJson(conv)

Expand Down
6 changes: 3 additions & 3 deletions src/jsons/timeline.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ proc createJsonApiTimelineRouter*(cfg: Config) =
if username.len > 0:
respJsonSuccess formatUserName(username)
else:
respJsonError "User not found"
respJsonError("User not found", "not_found", Http404)

get "/api/@name/profile":
cond @"name" notin ["pic", "gif", "video", "search", "settings", "login",
Expand All @@ -135,7 +135,7 @@ proc createJsonApiTimelineRouter*(cfg: Config) =
query.fromUser = names

var profile = await fetchProfile("", query, skipRail = false)
if profile.user.username.len == 0: respJsonError "User not found"
if profile.user.username.len == 0: respJsonError("User not found", "not_found", Http404)

respJsonSuccess formatProfileAsJson(profile)

Expand All @@ -160,6 +160,6 @@ proc createJsonApiTimelineRouter*(cfg: Config) =
respJsonSuccess formatTimelineAsJson(timeline)
else:
var profile = await fetchProfile(after, query, skipRail = true)
if profile.tweets.content.len == 0: respJsonError "User not found"
if profile.tweets.content.len == 0: respJsonError("User not found", "not_found", Http404)
profile.tweets.beginning = true
respJsonSuccess formatTimelineAsJson(profile.tweets)
8 changes: 5 additions & 3 deletions src/routes/router_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ template respJsonSuccess*(data: JsonNode) =
}
resp $successResponse, "application/json"

template respJsonError*(message: string) =
let errorResponse = %*{
template respJsonError*(message: string, errorType: string = "", httpCode: HttpCode = Http200) =
var errorResponse = %*{
"code": -1,
"error": message
}
resp $errorResponse, "application/json"
if errorType.len > 0:
errorResponse["error_type"] = %errorType
resp httpCode, $errorResponse, "application/json"

template respJsonNull*() =
let nullResponse = newJNull()
Expand Down
Loading