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(api.Body): fix bug that returns error when getting a peers body #533

Merged
merged 2 commits into from
Sep 4, 2018
Merged
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions api/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,13 @@ func (h DatasetHandlers) bodyHandler(w http.ResponseWriter, r *http.Request) {
}

if err := repo.CanonicalizeDatasetRef(h.repo, &d); err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, err)
// TODO: look through lib.LookupBody and see if we can refactor so it takes a datasetRef rather than just a path.
Copy link
Contributor

Choose a reason for hiding this comment

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

This bug is my fault (sorry!), but this is not the right fix. The semantics of CanonicalizeDatasetRef are weird because it's now basically doing two things. If the err returned is equal to repo.ErrNotFound, it means the ref was canonicalized but the dataset doesn't exist in the local repo. I made this change but forgot to update all the callers (whoops!). The correct thing to do here is to only send StateInternalServerError if err != nil && err != repo.ErrNotFound. As long as the dataset is remote, the rest of this code will handle it just fine by continuing onto LookupBody.

Copy link
Member Author

Choose a reason for hiding this comment

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

dope thanks!!!!

// We can then canonicalize down there and the cases of local vs peer dataset correctly\
// For now, if a datasetRef has a path, let's keep trying to get the data
if d.Path == "" {
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
}

limit, err := util.ReqParamInt("limit", r)
Expand Down Expand Up @@ -680,6 +686,6 @@ func (h DatasetHandlers) bodyHandler(w http.ResponseWriter, r *http.Request) {
Data: json.RawMessage(result.Data),
}
if err := util.WritePageResponse(w, dataResponse, r, page); err != nil {
log.Infof("error writing repsonse: %s", err.Error())
log.Infof("error writing response: %s", err.Error())
}
}