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

feat(gateway): improved error handling, support for 502 and 504 #182

Merged
merged 2 commits into from
Feb 24, 2023

Conversation

hacdias
Copy link
Member

@hacdias hacdias commented Feb 22, 2023

Improves the error handling for the gateway.

  • Ensures that the internalWebError goes through webError, which deferences into the correct error.
    • Removes internalWebError and just use webError instead.
  • Changes webError(w, message, error, code) to webError(w, err, code). The error should contain all the required information. In many places we were just duplicating the error information for no reason.
  • Adds a errors.Is for all the remaining errors to ensure we catch them all.
  • Adds a isErrNoLink. The reason why is explained in the comment.
  • Adds support for gateway timeout and bad gateway errors that can be bubbled up to the gateway.
  • ! returns 500 by default when name resolution errors instead of 400 (breaking).
  • Kubo PR feat(gateway): error handling improvements (500, 502, 504) kubo#9660

@codecov
Copy link

codecov bot commented Feb 22, 2023

Codecov Report

Merging #182 (c08d8f7) into main (6c0f842) will increase coverage by 0.75%.
The diff coverage is 47.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #182      +/-   ##
==========================================
+ Coverage   29.57%   30.32%   +0.75%     
==========================================
  Files         100      100              
  Lines       11241    11359     +118     
==========================================
+ Hits         3324     3445     +121     
+ Misses       7547     7540       -7     
- Partials      370      374       +4     
Impacted Files Coverage Δ
gateway/handler_block.go 0.00% <0.00%> (ø)
gateway/handler_car.go 0.00% <0.00%> (ø)
gateway/handler_codec.go 0.00% <0.00%> (ø)
gateway/handler_ipns_record.go 0.00% <0.00%> (ø)
gateway/handler_tar.go 0.00% <0.00%> (ø)
gateway/handler_unixfs.go 64.00% <0.00%> (-2.67%) ⬇️
gateway/handler_unixfs__redirects.go 39.34% <0.00%> (+0.54%) ⬆️
gateway/handler_unixfs_dir.go 65.10% <0.00%> (ø)
gateway/handler.go 69.44% <79.31%> (+6.69%) ⬆️
... and 1 more

@hacdias hacdias changed the title fix: ensure internalWebError goes through same error deferencing logic feat: improved error handling Feb 22, 2023
@hacdias hacdias changed the title feat: improved error handling feat: improved error handling and support for 502 and 504 Feb 22, 2023
@hacdias hacdias changed the title feat: improved error handling and support for 502 and 504 feat(gateway): improved error handling, support for 502 and 504 Feb 22, 2023
@hacdias hacdias self-assigned this Feb 22, 2023
@hacdias hacdias marked this pull request as ready for review February 22, 2023 13:51
@hacdias hacdias requested a review from lidel as a code owner February 22, 2023 13:51
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

Thank you, finally human-readable errors! 🙃

I had no time to take it for a spin, but dropped some small asks below and for:

! returns 500 by default when name resolution errors instead of 400 (breaking).

See my question in ipfs/kubo#9660 (comment)

gateway/handler.go Outdated Show resolved Hide resolved
gateway/handler.go Outdated Show resolved Hide resolved
gateway/handler_codec.go Outdated Show resolved Hide resolved
gateway/handler_tar.go Outdated Show resolved Hide resolved
gateway/handler_test.go Outdated Show resolved Hide resolved
gateway/handler_test.go Outdated Show resolved Hide resolved
gateway/handler_unixfs.go Outdated Show resolved Hide resolved
gateway/handler_tar.go Outdated Show resolved Hide resolved
gateway/handler.go Outdated Show resolved Hide resolved
I believe the context timeouts gateway code will hit are not related to client not sending data, so 408 was invalid here.
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

Thank you @hacdias, let's bubble this up to bifrost-gateway.

I filled #185 to investigate 400vs500 test issue in Kubo (but we dont want to block bifrost-gateway on this)

@lidel lidel merged commit 00e0249 into main Feb 24, 2023
@lidel lidel deleted the improved-error-handling branch February 24, 2023 15:26
lidel pushed a commit to ipfs/kubo that referenced this pull request Feb 24, 2023
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
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants