Mercurial Hosting > linkmystyle
diff src/error_log.js.luan @ 0:8f4df159f06b
start public repo
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 11 Jul 2025 20:57:49 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/error_log.js.luan Fri Jul 11 20:57:49 2025 -0600 @@ -0,0 +1,60 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local String = require "luan:String.luan" +local trim = String.trim or error() +local regex = String.regex or error() +local contains = String.contains or error() +local Table = require "luan:Table.luan" +local concat = Table.concat or error() +local Http = require "luan:http/Http.luan" +local Logging = require "luan:logging/Logging.luan" +local logger = Logging.logger "error_log.js" + + +local bad_agents = { + [[Googlebot]] + [[GSA/]] + [[Mobile/15E148 Instagram]] + [[Firefox/]] + [[VivoBrowser/]] + [[Chrome/(4\d|5\d|70|83|86|87|94)\.]] + [[musical_ly_2\d\.]] +} +local bad_agents_ptn = regex(concat(bad_agents,"|")) + +local bad_contents = { + [[\Qchrome-extension://\E]] + [[\Q@webkit-masked-url://hidden/\E]] + [[\Qanalytics.tiktok.com\E]] + [[\QStrict mode does not allow function declarations in a lexically nested statement.\E]] + [[\QFailed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite.\E]] + [[\QThe element has no supported sources.\E]] + [[\QThe play() request was interrupted by a call to pause().\E]] + [[\QReferenceError: Can't find variable: _AutofillCallbackHandler\E]] + [[\QUtilityScript\E]] + [[\QscrollReadRandom\E]] + [[\QdoGameClick\E]] + [[\Qurl = undefined\E]] + [[\QFailed to set remote answer sdp: The order of m-lines in answer doesn't match order in offer. Rejecting answer.\E]] +} +local bad_contents_ptn = regex(concat(bad_contents,"|")) + +local function priority(err) + local agent = Http.request.headers["user-agent"] + if agent~=nil and bad_agents_ptn.matches(agent) then return "info" end + if bad_contents_ptn.matches(err) then return "info" end + local x_requested_with = Http.request.headers["X-Requested-With"] + if x_requested_with ~= nil then + return "info" + 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