diff --git a/scripts/wx_download.lua b/scripts/wx_download.lua index cf73439..713cb71 100644 --- a/scripts/wx_download.lua +++ b/scripts/wx_download.lua @@ -10,7 +10,6 @@ local function get_access_token() local host = ngx.var.host local wx_domain = ngx.var.wx_domain - ngx.log(ngx.INFO, "Request URL -> ", ngx.var.uri) ngx.log(ngx.INFO, "HTYUC -> ", htyuc) ngx.log(ngx.INFO, "Host -> ", host) ngx.log(ngx.INFO, 'HtyHostHeader -> ', htyhostHeader) @@ -36,6 +35,7 @@ local function get_access_token() if no_exception == true then if 200 ~= resp.status then ngx.log(ngx.ERR, "GET ACCESS TOKEN *FAILED*", pl.write(resp_err)) + ngx.status = resp.status ngx.say(pl.write(resp_err)) ngx.exit(resp.status) else @@ -47,7 +47,10 @@ local function get_access_token() resp = "" end ngx.log(ngx.ERR, "FAILED TO CONNECT TO *HTYUC*: httpc throws runtime error, please check HTYUC log. / ", pl.write(resp)) - ngx.say(pl.write(resp)) + -- 必须先设置ngx.status,否则ngx.say之后就直接被设置为200了,不会再被exit设为401 + -- https://github.com/openresty/lua-resty-redis/issues/15 + ngx.status = 401 + ngx.say(cjson.encode({r = false, d = "HtySudoerTokenErr"})) ngx.exit(401) end end @@ -64,12 +67,14 @@ local function get_wx_media(media_id) if resp == nil then ngx.log(ngx.ERR, "FAILED TO CONNECT TO *Weixin*", req_err) + ngx.status = 500 ngx.say(req_err) ngx.exit(500) end if 200 ~= resp.status then ngx.log(ngx.ERR, 'GET WECHET MEDIA *FAILED*', req_err) + ngx.status = resp.status ngx.say(req_err) ngx.exit(resp.status) end