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 Colorize.with.light_gray.dim.surround(@io) do
timestamp timestamp
end end
string " " string " "
severity_color(@entry.severity).surround(@io) do severity_color(@entry.severity).surround(@io) do
@entry.severity.label.rjust(@io, 6) @entry.severity.label.rjust(@io, 6)
end end
string ": " string " "
Colorize.with.white.surround(@io) do Colorize.with.white.surround(@io) do
source source
end end
string " - " string " "
message message
end end
end end
@ -97,10 +97,27 @@ module CrystalGauntlet
if CrystalGauntlet.endpoints.has_key?(path) && context.request.method == "POST" && body if CrystalGauntlet.endpoints.has_key?(path) && context.request.method == "POST" && body
func = CrystalGauntlet.endpoints[path] func = CrystalGauntlet.endpoints[path]
value = func.call(body.gets_to_end) begin
LOG.debug { "-> " + value } value = func.call(body.gets_to_end)
context.response.content_type = "text/plain" rescue err
context.response.print value 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 else
call_next(context) call_next(context)
end end
@ -109,9 +126,8 @@ module CrystalGauntlet
def self.run() def self.run()
server = HTTP::Server.new([ server = HTTP::Server.new([
HTTP::ErrorHandler.new,
HTTP::LogHandler.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 CrystalGauntlet::GDHandler.new
]) ])

View file

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