Divide the MSB source codes into two repos
[msb/apigateway.git] / openresty-ext / src / assembly / resources / openresty / nginx / luaext / lib / utils / error_handler.lua
1 --[[\r
2 \r
3     Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
4 \r
5     Licensed under the Apache License, Version 2.0 (the "License");\r
6     you may not use this file except in compliance with the License.\r
7     You may obtain a copy of the License at\r
8 \r
9             http://www.apache.org/licenses/LICENSE-2.0\r
10 \r
11     Unless required by applicable law or agreed to in writing, software\r
12     distributed under the License is distributed on an "AS IS" BASIS,\r
13     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14     See the License for the specific language governing permissions and\r
15     limitations under the License.\r
16 \r
17 --]]\r
18 \r
19 local _M = {}\r
20 _M._VERSION = '1.0.0'\r
21 local msbConf   =  require('conf.msbinit')\r
22 local enablefullsearch = msbConf.systemConf.enablefullsearch\r
23 local ngx_var = ngx.var\r
24 local error_page_head = '<html><head><title>502 Bad Gateway</title></head><body bgcolor="white"><center><h1>502 Bad Gateway</h1></center><center>error message:'\r
25 local error_page_foot = '</center><hr><center>nginx</center></body></html>'\r
26 local upstream_not_found_err = "service info is incorrect:using own upstream flag is on but upstream name is empty"\r
27 \r
28 function _M.svc_not_found(err_info,detail_info)\r
29         ngx.log(ngx.WARN, ngx.var.request_id.." "..(err_info or "").." detail_info:"..(detail_info or ""))\r
30         if enablefullsearch and ngx_var.svc_type ~= "custom" then\r
31                 -- test against the custom services after the commonrewrite phase\r
32                 --ngx.status = ngx.HTTP_GONE\r
33                 return ngx.exec("@commonnotfound");\r
34         else\r
35                 ngx.status = ngx.HTTP_BAD_GATEWAY\r
36                 ngx.print(error_page_head..err_info..error_page_foot)\r
37         end\r
38         return ngx.exit(ngx.status)\r
39 end\r
40 \r
41 function _M.upstream_not_found()\r
42         ngx.log(ngx.WARN, ngx.var.request_id.." "..upstream_not_found_err)\r
43         ngx.status = ngx.HTTP_BAD_GATEWAY\r
44         ngx.print(error_page_head..upstream_not_found_err..error_page_foot)\r
45         return ngx.exit(ngx.status)\r
46 end\r
47 \r
48 return _M