魔改json库,最后套一层pcall防止致命错误
This commit is contained in:
@@ -68,6 +68,7 @@ return{
|
||||
registerSuccessed="Registered!",
|
||||
registerFailed="Registration failed",
|
||||
netErrorCode="Network error code",
|
||||
jsonError="Json error",
|
||||
noUsername="Please enter your username",
|
||||
wrongEmail="Wrong email address",
|
||||
noPassword="Please enter your password",
|
||||
|
||||
@@ -68,6 +68,7 @@ return{
|
||||
registerSuccessed="Register successed!",
|
||||
registerFailed="Register failed",
|
||||
netErrorCode="Network error code",
|
||||
jsonError="Json error",
|
||||
noUsername="Input username",
|
||||
wrongEmail="Wrong email address",
|
||||
noPassword="Input password",
|
||||
|
||||
@@ -68,6 +68,7 @@ return{
|
||||
registerSuccessed="注册成功!",
|
||||
registerFailed="注册失败",
|
||||
netErrorCode="网络错误码",
|
||||
jsonError="json错误",
|
||||
noUsername="请填写用户名",
|
||||
wrongEmail="邮箱格式错误",
|
||||
noPassword="请填写密码",
|
||||
|
||||
@@ -300,7 +300,9 @@ do--json
|
||||
error("unexpected type '" .. t .. "'")
|
||||
end
|
||||
|
||||
function json.encode(val) return encode(val) end
|
||||
function json.encode(val)
|
||||
return pcall(encode,val)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Decode
|
||||
@@ -516,7 +518,7 @@ do--json
|
||||
decode_error(str, idx, "unexpected character '" .. chr .. "'")
|
||||
end
|
||||
|
||||
function json.decode(str)
|
||||
local function decode(str)
|
||||
if type(str) ~= "string" then
|
||||
error("expected argument of type string, got " .. type(str))
|
||||
end
|
||||
@@ -525,6 +527,9 @@ do--json
|
||||
if idx <= #str then decode_error(str, idx, "trailing garbage") end
|
||||
return res
|
||||
end
|
||||
function json.decode(str)
|
||||
return pcall(decode,str)
|
||||
end
|
||||
end
|
||||
function copyList(org)
|
||||
local L={}
|
||||
|
||||
@@ -78,12 +78,16 @@ function Tick.httpREQ_launch(data)
|
||||
local res,err=client.poll(data.task)
|
||||
if res then
|
||||
if res.code==200 then
|
||||
res=json.decode(res.body)
|
||||
LOG.print(res.notice,360,color.sky)
|
||||
if gameVersion==res.version then
|
||||
LOG.print(text.versionIsNew,360,color.sky)
|
||||
err,res=json.decode(res.body)
|
||||
if res then
|
||||
LOG.print(res.notice,360,color.sky)
|
||||
if gameVersion==res.version then
|
||||
LOG.print(text.versionIsNew,360,color.sky)
|
||||
else
|
||||
LOG.print(string.gsub(text.versionIsOld,"$1",res.version),"warn")
|
||||
end
|
||||
else
|
||||
LOG.print(string.gsub(text.versionIsOld,"$1",res.version),"warn")
|
||||
LOG.print(text.jsonError..": "..err,"warn")
|
||||
end
|
||||
else
|
||||
LOG.print(text.netErrorCode..res.code,"warn")
|
||||
@@ -103,11 +107,15 @@ function Tick.httpREQ_register(data)
|
||||
local res,err=client.poll(data.task)
|
||||
if res then
|
||||
if res.code==200 then
|
||||
res=json.decode(res.body)
|
||||
if res.status then
|
||||
LOG.print(text.registerSuccessed)
|
||||
err,res=json.decode(res.body)
|
||||
if res then
|
||||
if res.status then
|
||||
LOG.print(text.registerSuccessed)
|
||||
else
|
||||
LOG.print(text.registerFailed..": "..res.msg)
|
||||
end
|
||||
else
|
||||
LOG.print(text.registerFailed..": "..res.msg)
|
||||
LOG.print(text.jsonError..": "..err,"warn")
|
||||
end
|
||||
else
|
||||
LOG.print(text.netErrorCode..res.code,"warn")
|
||||
|
||||
Reference in New Issue
Block a user