Skip to content
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

JSON as response for 404 not found #12305

Merged
merged 7 commits into from
Nov 18, 2020
Merged

Conversation

Zedmor
Copy link
Contributor

@Zedmor Zedmor commented Nov 12, 2020

In case of existing issue, reference it using one of the following:

closes: #12131

JSON is not returned for API requests with incorrect endpoint

Reason of 12131 is happening is that blueprint level handlers are not possible for 404 and 405. See references:

https://stackoverflow.com/questions/58728366/python-flask-error-handling-with-blueprints
pallets/flask#1935

and therefore 404 exception handling spill out to application level handler (circles).

I am looking forward to better implementation but this works.

 ~  curl http://localhost:5000/api/v1/daggggs
{
  "detail": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
  "status": 404,
  "title": "Not Found",
  "type": "about:blank"
 ~  curl http://localhost:5000/fafs          


<!DOCTYPE html>
<html>
<head>
  <title>Airflow 404 = lots of circles</title>

…y could be handled by Flask and therefore we need to handle it ourselves.
@boring-cyborg boring-cyborg bot added the area:webserver Webserver related Issues label Nov 12, 2020
@github-actions
Copy link

The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.

@mik-laj
Copy link
Member

mik-laj commented Nov 12, 2020

@Zedmor can you fix the CI? It is very important to us because it is the first criterion on the basis of which we review PR.

@@ -134,12 +134,29 @@ def init_error_handlers(app: Flask):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We override handler only for API, therefore in case we will build it w/o API default handler (with circles) should still be applied. 500 is handled properly by blueprint handler (with JSONify) btw, only 404 and 405 are not.

# unless raised from a view func so actual 404 errors,
# i.e. "no route for it" defined, need to be handled
# here on the application level
return common_error_handler(ex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is common_error_handler support this exception type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, see

404: f"{doc_link}#section/Errors/NotFound",

problem is that flask do not delegate that to common error handler from blueprint (connexion)

@mik-laj
Copy link
Member

mik-laj commented Nov 12, 2020

Awesome! Thank you for taking care of it so quickly. Can you also add automated tests to prevent regression?

@github-actions
Copy link

The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.

@ephraimbuddy
Copy link
Contributor

Can issue #12325 be resolved through this PR? You'll just need to update

EXCEPTIONS_LINK_MAP = {
and add the error in openapi specification.

I can see 405 handled in your code, but there's no corresponding link in openapi

@Zedmor
Copy link
Contributor Author

Zedmor commented Nov 13, 2020

Can issue #12325 be resolved through this PR? You'll just need to update

EXCEPTIONS_LINK_MAP = {

and add the error in openapi specification.
I can see 405 handled in your code, but there's no corresponding link in openapi

Yes, it handles it. I put it to link map but it handle it anyway since link map is just a way to generate link to a documentation (we can add it later).

I added the test to check for 405 for issue #12325

@github-actions
Copy link

The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.

@github-actions
Copy link

The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.

@ephraimbuddy
Copy link
Contributor

Nice! Please also add the Method Not Allowed description here: https://github.com/apache/airflow/blob/master/airflow/api_connexion/openapi/v1.yaml,

You'll see an example

@ephraimbuddy
Copy link
Contributor

Nitpicking here. Something like this would be a nice addition:

@github-actions
Copy link

The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.

@mik-laj mik-laj merged commit 966ee7d into apache:master Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:webserver Webserver related Issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return Json for all Not Found views in REST API
3 participants