trending error fix, make errors actually log

This commit is contained in:
Jill 2023-01-02 17:00:04 +03:00
parent d4e930e424
commit 551bc7cbcf
2 changed files with 26 additions and 10 deletions

View File

@ -71,15 +71,15 @@ module CrystalGauntlet
Colorize.with.light_gray.dim.surround(@io) do
timestamp
end
string " "
string " "
severity_color(@entry.severity).surround(@io) do
@entry.severity.label.rjust(@io, 6)
end
string ": "
string " "
Colorize.with.white.surround(@io) do
source
end
string " - "
string " "
message
end
end
@ -97,10 +97,27 @@ module CrystalGauntlet
if CrystalGauntlet.endpoints.has_key?(path) && context.request.method == "POST" && body
func = CrystalGauntlet.endpoints[path]
value = func.call(body.gets_to_end)
LOG.debug { "-> " + value }
context.response.content_type = "text/plain"
context.response.print value
begin
value = func.call(body.gets_to_end)
rescue err
LOG.error { "error while handling #{path}:" }
LOG.error { err.to_s }
is_relevant = true
err.backtrace.each do |str|
# this is a hack. Oh well
if str.starts_with?("src/crystal-gauntlet.cr") || (!is_relevant)
is_relevant = false
else
LOG.error {" #{str}"}
end
end
context.response.content_type = "text/plain"
context.response.respond_with_status(500, "-1")
else
LOG.debug { "-> " + value }
context.response.content_type = "text/plain"
context.response.print value
end
else
call_next(context)
end
@ -109,9 +126,8 @@ module CrystalGauntlet
def self.run()
server = HTTP::Server.new([
HTTP::ErrorHandler.new,
HTTP::LogHandler.new,
HTTP::StaticFileHandler.new("data/", fallthrough = true, directory_listing = false),
HTTP::StaticFileHandler.new("data/", fallthrough: true, directory_listing: false),
CrystalGauntlet::GDHandler.new
])

View File

@ -102,7 +102,7 @@ CrystalGauntlet.endpoints["/getGJLevels21.php"] = ->(body : String): String {
when "3" # trending
# todo: make configurable?
order = "likes desc"
queryParams << "created_at > #{(Time.utc - 7.days).to_s(Format::TIME_FORMAT)}"
queryParams << "levels.created_at > \"#{(Time.utc - 7.days).to_s(Format::TIME_FORMAT)}\""
when "5" # made by user
queryParams << "levels.user_id = #{searchQuery.to_i}" # (you can't sql inject with numbers)
when "6", "17" # featured (gdw is 17)