Skip to content

Commit

Permalink
change: responsed a better tip when failed to match any route. (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
membphis authored and SaberMaster committed Jun 30, 2020
1 parent 7733839 commit d77280c
Show file tree
Hide file tree
Showing 29 changed files with 105 additions and 117 deletions.
2 changes: 1 addition & 1 deletion lua/apisix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function _M.http_access_phase()

local route = api_ctx.matched_route
if not route then
return core.response.exit(404)
return core.response.exit(404, {error_msg = "failed to match any routes"})
end

if route.value.service_protocol == "grpc" then
Expand Down
2 changes: 1 addition & 1 deletion lua/apisix/http/router/radixtree_host_uri.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function _M.match(api_ctx)
end

core.log.info("not find any matched route")
return core.response.exit(404)
return true
end


Expand Down
4 changes: 2 additions & 2 deletions lua/apisix/http/router/radixtree_uri.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function _M.match(api_ctx)

if not uri_router then
core.log.error("failed to fetch valid `uri` router: ")
return core.response.exit(404)
return true
end

core.table.clear(match_opts)
Expand All @@ -110,7 +110,7 @@ function _M.match(api_ctx)
local ok = uri_router:dispatch(api_ctx.var.uri, match_opts, api_ctx)
if not ok then
core.log.info("not find any matched route")
return core.response.exit(404)
return true
end

return true
Expand Down
4 changes: 2 additions & 2 deletions t/debug/hook.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
8 changes: 4 additions & 4 deletions t/node/global-rule.t
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand All @@ -104,8 +104,8 @@ qr/404 Not Found/
--- request
GET /hello
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
8 changes: 4 additions & 4 deletions t/node/hosts.t
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand All @@ -77,8 +77,8 @@ GET /hello
--- more_headers
Host: not_found.com
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
4 changes: 2 additions & 2 deletions t/node/invalid-route.t
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ qr/"value":"mexxxxxxxxxxxxxxx"/
--- request
GET /not_found
--- error_code: 404
--- response_body_like eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- grep_error_log eval
qr/\[error\].*/
--- grep_error_log_out eval
Expand Down
4 changes: 2 additions & 2 deletions t/node/invalid-service.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ qr/"value":"mexxxxxxxxxxxxxxx"/
--- request
GET /not_found
--- error_code: 404
--- response_body_like eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- grep_error_log eval
qr/\[error\].*/
--- grep_error_log_out eval
Expand Down
4 changes: 2 additions & 2 deletions t/node/invalid-upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ qr/"value":"mexxxxxxxxxxxxxxx"/
--- request
GET /not_found
--- error_code: 404
--- response_body_like eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- grep_error_log eval
qr/\[error\].*/
--- grep_error_log_out eval
Expand Down
4 changes: 2 additions & 2 deletions t/node/merge-route.t
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
2 changes: 1 addition & 1 deletion t/node/not-exist-service.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ passed
--- request
GET /hello
--- error_code: 404
--- response_body_like eval
--- response_body eval
qr/404 Not Found/
--- wait_etcd_sync: 0.3
--- grep_error_log eval
Expand Down
4 changes: 2 additions & 2 deletions t/node/not-exist-upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body_like eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
12 changes: 6 additions & 6 deletions t/node/remote-addr-ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ location /t {
}
--- request
GET /t
--- response_body_like eval
qr{.*404 Not Found.*}
--- response_body eval
qr/"error_msg":"failed to match any routes"/
--- no_error_log
[error]
Expand All @@ -89,8 +89,8 @@ qr{.*404 Not Found.*}
--- request
GET /not_found
--- error_code: 404
--- response_body_like eval
qr{.*404 Not Found.*}
--- response_body eval
qr/"error_msg":"failed to match any routes"/
--- no_error_log
[error]
Expand Down Expand Up @@ -129,7 +129,7 @@ close: 1 nil
--- request
GET /hello
--- error_code: 404
--- response_body_like eval
qr{.*404 Not Found.*}
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
8 changes: 4 additions & 4 deletions t/node/remote-addr.t
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down Expand Up @@ -117,8 +117,8 @@ passed
--- request
GET /hello
--- error_code: 404
--- response_body_like eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
6 changes: 2 additions & 4 deletions t/node/remote_addrs.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ set_real_ip_from unix:;
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand All @@ -85,8 +85,6 @@ GET /hello
--- more_headers
Host: not_found.com
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- no_error_log
[error]
Expand Down
4 changes: 2 additions & 2 deletions t/node/route-domain.t
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
4 changes: 2 additions & 2 deletions t/node/route-filter-func.t
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ passed
--- request
GET /hello?name=unknown
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
12 changes: 6 additions & 6 deletions t/node/route-host.t
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand All @@ -76,8 +76,8 @@ qr/404 Not Found/
--- request
GET /hello
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand All @@ -89,8 +89,8 @@ GET /hello
--- more_headers
Host: not_found.com
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
2 changes: 0 additions & 2 deletions t/node/route-uris.t
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- no_error_log
[error]
Expand Down
8 changes: 4 additions & 4 deletions t/node/sanity-radixtree.t
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down Expand Up @@ -149,7 +149,7 @@ qr/404 Not Found/
--- request
GET /hel
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
4 changes: 2 additions & 2 deletions t/node/upstream-domain.t
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
4 changes: 2 additions & 2 deletions t/node/upstream-ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
4 changes: 2 additions & 2 deletions t/node/upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ passed
--- request
GET /not_found
--- error_code: 404
--- response_body eval
qr/404 Not Found/
--- response_body
{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
Expand Down
Loading

0 comments on commit d77280c

Please sign in to comment.