view src/error_log.js.luan @ 13:24668255cede

preprocess urls
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 Jul 2022 23:59:41 -0600
parents 0472897e790d
children a1db5223ced1
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local String = require "luan:String.luan"
local matches = String.matches or error()
local trim = String.trim or error()
local Table = require "luan:Table.luan"
local Http = require "luan:http/Http.luan"
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "error_log"

--[=[ when needed
local bad_bots = {
	[[Googlebot]]
	[[bingbot]]
}
local bad_bots_ptn = Table.concat(bad_bots,"|")
]=]

local function priority(err)
--[=[
	local agent = Http.request.headers["user-agent"]
	if agent~=nil and matches(agent,bad_bots_ptn) then return "info" end
	if matches(err,[[Uncaught TypeError: Illegal invocation]]) then return "warn" end
	if matches(err,[[\Q?fbclid=\E]]) then return "warn" end
]=]
	return "error"
end

return function()
	local err = Http.request.parameters.err
	if err == nil then
		return  -- stupid bots
	end
	local call = priority(err)
	logger[call](trim(err).."\n"..trim(Http.request.raw_head).."\n")
end