-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add 5xx error page #3883
feat: add 5xx error page #3883
Conversation
t/cli/test_error_page.sh
Outdated
. ./t/cli/common.sh | ||
|
||
git checkout conf/config.yaml | ||
make init |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need it if we call make run
later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
you can merge the master branch |
t/cli/test_error_page.sh
Outdated
echo "failed: the error page is not customized" | ||
exit 1 | ||
fi | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also add some test cases that an upstream returns 5xx
but these error pages are not shown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
ci failed now |
@@ -233,6 +233,9 @@ http { | |||
{% end %} | |||
{% end %} | |||
|
|||
# error_page | |||
error_page 500 502 503 504 @apisix_error_handler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about the 4xx response codes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we do need it.
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>openresty</center>
</body>
</html>
Maybe we can add a link in the response first.
apisix/error_handler.lua
Outdated
<p>If you are the system administrator of this resource then you should check | ||
the <a href="https://github.com/apache/apisix/blob/master/conf/config-default.yaml#L135">error log | ||
</a> for details.</p> | ||
<p>If you need any help, click <a href="https://apisix.apache.org/">need help</a>.</em></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this link can help users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
https://apisix.apache.org/help/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same to #3883 (comment)
Please fix it when you have time @starsz . |
Need some time.A little busy lately. |
Of course, we need the 4xx page.
Thanks,
Ming Wen
Twitter: _WenMing
Peter Zhu ***@***.***> 于2021年4月1日周四 下午12:45写道:
… ***@***.**** commented on this pull request.
------------------------------
In apisix/cli/ngx_tpl.lua
<#3883 (comment)>:
> @@ -233,6 +233,9 @@ http {
{% end %}
{% end %}
+ # error_page
+ error_page 500 502 503 504 @apisix_error_handler;
Now the 4xx situation like:
404: {"error_msg":"404 Route Not Found"}
401: {"code":4107,"message":"request
unauthorized","data":null,"request_id":""}
We will return JSON, do this need to add an error page?
IMO, it doesn't need now.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3883 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGJZBK23EDVVWLBE5EIVAJLTGP26BANCNFSM4ZUF3MSA>
.
|
apisix/error_handler.lua
Outdated
@@ -50,5 +50,4 @@ return function() | |||
if ngx.status >= 500 and ngx.status <= 599 then | |||
ngx.say(html_5xx) | |||
end | |||
end | |||
|
|||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check your editor, end of line symbol is required.
ping @starsz |
t/cli/test_error_page.sh
Outdated
sleep 0.1 | ||
|
||
# set route | ||
code=$(curl -XPUT -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -d '{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused why you don't test them by Test::Nginx.
ping @starsz I am going to close this pr, there is no feedback for too long |
Better not, I will finish it this weekend. |
local ngx_status_line = { | ||
[400] = "400 Bad Request", | ||
[401] = "401 Unauthorized", | ||
[403] = "403 Forbidden", | ||
[404] = "404 Not Found", | ||
[405] = "405 Not Allowed", | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we should add it into 4xx html.
I can't find any API that contains this info.
@tokers @spacewander Do you have any opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show status code in body is useful in the browser, I think we can reserve it.
t/error_handler/error_handler.t
Outdated
=== TEST 12: test apisix with upstream error code 400 | ||
--- request | ||
GET /specific_status | ||
--- more_headers | ||
X-Test-Upstream-Status: 400 | ||
--- error_code: 400 | ||
--- response_body | ||
upstream status: 400 | ||
|
||
|
||
|
||
=== TEST 11: test apisix with upstream error code 500 | ||
--- request | ||
GET /specific_status | ||
--- more_headers | ||
X-Test-Upstream-Status: 500 | ||
--- error_code: 500 | ||
--- response_body | ||
upstream status: 500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a little confused, why do special treatments for upstream status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a mock that I mock the upstream status.
You can see t/lib/server.lua
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, why doesn’t the upstream 5xx show the 5xx page of Apache APISIX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, why doesn’t the upstream 5xx show the 5xx page of Apache APISIX?
The upstream 5xx has its own mean.There maybe contains the error info like `{"code": 5xx, "error_msg": "xxx"}.
So IMO we shouldn't modify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do users need to care about the error of the Apache APISIX or the upstream error? I remember that there are already corresponding HTTP headers to distinguish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some situations. The info in the response body is useful. The user will need the upstream error info.
cc @tokers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moonming We should keep the upstream 4xx/5xx pages intact by default, but we may add a switch like:
proxy_intercept_errors on | off;
This is a standard Nginx directive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR, what was the data returned by 5xx and 4xx?
I have no other questions but one:
For |
any response? @starsz |
Let me test and list the response. |
The internal error:
502:
503:
504:
400:
401:
404:
|
Then your PR did not solve the issue @starsz |
please read the issue again |
I am confused. This PR can solve the issue. The response I give is before this PR. By the way, I will fix the CI first. |
please make sure you read the issue and thread in mailinglist |
@starsz Conflicts should be resolved. |
Hi, @moonming.I read the email again. The openresty updated the 50x.html.
So that we can see the HTML that updated by the openresty. But in apisix, we don't set the BTW, I think my implementation is too complicated. Can we create html directory and put our html in it? Then we can get the html if an error occurred. |
any update? |
@starsz ping |
Use another PR #4164 to fix this issue. |
What this PR does / why we need it:
Show our own HTML page, when the apisix self returns 5xx.
fix #3251
Pre-submission checklist: