Skip to content

fix(gw): 404 when a valid DAG is missing link#9126

Merged
lidel merged 1 commit into
masterfrom
fix/gw-errors-400-404
Jul 22, 2022
Merged

fix(gw): 404 when a valid DAG is missing link#9126
lidel merged 1 commit into
masterfrom
fix/gw-errors-400-404

Conversation

@lidel

@lidel lidel commented Jul 19, 2022

Copy link
Copy Markdown
Member

This PR makes sure gateway returns 404 (Not Found) only when a valid DAG is missing the requested child.
In other cases, 400 (Bad Request) is returned.

Uses ipld.IsNotFound added in #8838

Closes #8924
Closes #9064

@lidel lidel self-assigned this Jul 19, 2022
Comment on lines +785 to +786
} else if ipld.IsNotFound(err) {
webErrorWithCode(w, message, err, http.StatusNotFound)

@lidel lidel Jul 19, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ℹ️ this makes sure every webError gets 404 when appropriate (even when it was called with http.StatusBadRequest)

@lidel lidel force-pushed the fix/gw-errors-400-404 branch from 76c3f13 to 7062162 Compare July 19, 2022 20:36
@lidel lidel requested review from Jorropo and iand July 19, 2022 20:38
@lidel lidel marked this pull request as ready for review July 19, 2022 20:39
@lidel lidel force-pushed the fix/gw-errors-400-404 branch from 7062162 to be10c71 Compare July 20, 2022 15:31

@iand iand left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

{"127.0.0.1:8080", k.String(), http.StatusOK, "fnord"},
{"127.0.0.1:8080", "/ipns/nxdomain.example.com", http.StatusNotFound, "ipfs resolve -r /ipns/nxdomain.example.com: " + namesys.ErrResolveFailed.Error() + "\n"},
{"127.0.0.1:8080", "/ipns/%0D%0A%0D%0Ahello", http.StatusNotFound, "ipfs resolve -r /ipns/\\r\\n\\r\\nhello: " + namesys.ErrResolveFailed.Error() + "\n"},
{"127.0.0.1:8080", "/ipns/nxdomain.example.com", http.StatusBadRequest, "ipfs resolve -r /ipns/nxdomain.example.com: " + namesys.ErrResolveFailed.Error() + "\n"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note I think resolution errors should be reported as 502 Bad Gateway but that's not what the gateway spec says. I'll raise an issue there instead

@lidel lidel Jul 22, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Continued in ipfs/specs#300 👍

@lidel lidel force-pushed the fix/gw-errors-400-404 branch from be10c71 to 0918d57 Compare July 22, 2022 22:04
@lidel lidel merged commit 7992025 into master Jul 22, 2022
@lidel lidel deleted the fix/gw-errors-400-404 branch July 22, 2022 22:16
@BigLep BigLep mentioned this pull request Jul 26, 2022
68 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

Gateway incorrectly reports NotFound when any error encountered reading UnixFS Investigate why /ipfs/{invalid cid} returns different Status Code now

2 participants