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

fix(gw): blocked content produces http error 410 #497

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gateway/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
code = http.StatusBadRequest
case isErrNotFound(err):
code = http.StatusNotFound
case isErrContentBlocked(err):
code = http.StatusGone

Check warning on line 153 in gateway/errors.go

View check run for this annotation

Codecov / codecov/patch

gateway/errors.go#L152-L153

Added lines #L152 - L153 were not covered by tests
case errors.Is(err, context.DeadlineExceeded):
code = http.StatusGatewayTimeout
}
Expand Down Expand Up @@ -202,3 +204,10 @@
}
}
}

// isErrContentBlocked returns true for content filtering system errors
func isErrContentBlocked(err error) bool {
// TODO: we match error message to avoid pulling nopfs as a dependency
// Ref. https://github.com/ipfs-shipyard/nopfs/blob/cde3b5ba964c13e977f4a95f3bd8ca7d7710fbda/status.go#L87-L89
return strings.Contains(err.Error(), "blocked and cannot be provided")
}
Loading