Skip to content

Commit

Permalink
Merge branch 'main' into chore/migrate-bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero authored Oct 30, 2023
2 parents 9048c01 + 341c7da commit 5ee3a08
Showing 1 changed file with 9 additions and 0 deletions.
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 @@ func webError(w http.ResponseWriter, r *http.Request, c *Config, err error, defa
code = http.StatusBadRequest
case isErrNotFound(err):
code = http.StatusNotFound
case isErrContentBlocked(err):
code = http.StatusGone
case errors.Is(err, context.DeadlineExceeded):
code = http.StatusGatewayTimeout
}
Expand Down Expand Up @@ -202,3 +204,10 @@ func isErrNotFound(err error) bool {
}
}
}

// 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")
}

0 comments on commit 5ee3a08

Please sign in to comment.