Skip to content

Commit

Permalink
fix(fsi): Cleanup error handling and some if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Aug 15, 2019
1 parent 29606ea commit 2feb0ab
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
19 changes: 9 additions & 10 deletions api/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ func (h *DatasetHandlers) getHandler(w http.ResponseWriter, r *http.Request) {
}
res := lib.GetResult{}
err := h.Get(&p, &res)
if err == repo.ErrNoHistory {
NoHistoryErrResponse(w)
return
}
if err != nil {
if err == repo.ErrNoHistory {
NoHistoryErrResponse(w)
return
}
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
Expand Down Expand Up @@ -619,12 +619,11 @@ func (h DatasetHandlers) bodyHandler(w http.ResponseWriter, r *http.Request) {
}

result := &lib.GetResult{}
err = h.Get(p, result)
if err == repo.ErrNoHistory {
NoHistoryErrResponse(w)
return
}
if err != nil {
if err := h.Get(p, result); err != nil {
if err == repo.ErrNoHistory {
NoHistoryErrResponse(w)
return
}
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
Expand Down
25 changes: 13 additions & 12 deletions api/fsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,28 @@ func (h *FSIHandlers) statusHandler(routePrefix string) http.HandlerFunc {
}

res := []lib.StatusItem{}
if !useFSI {
refStr := ref.String()
err = h.StatusAtVersion(&refStr, &res)
if err == repo.ErrNoHistory {
NoHistoryErrResponse(w)
return
}
if err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, fmt.Errorf("error getting status: %s", err.Error()))
return
}
} else {
if useFSI {
alias := ref.AliasString()
err := h.StatusForAlias(&alias, &res)
// Won't return ErrNoHistory.
if err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, fmt.Errorf("error getting status: %s", err.Error()))
return
}
util.WriteResponse(w, res)
return
}

refStr := ref.String()
err = h.StatusAtVersion(&refStr, &res)
if err != nil {
if err == repo.ErrNoHistory {
NoHistoryErrResponse(w)
return
}
util.WriteErrResponse(w, http.StatusInternalServerError, fmt.Errorf("error getting status: %s", err.Error()))
return
}
util.WriteResponse(w, res)
}
}
Expand Down
11 changes: 5 additions & 6 deletions api/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ func (h *LogHandlers) logHandler(w http.ResponseWriter, r *http.Request) {
}

res := []repo.DatasetRef{}
err = h.Log(params, &res)
if err == repo.ErrNoHistory {
NoHistoryErrResponse(w)
return
}
if err != nil {
if err := h.Log(params, &res); err != nil {
if err == repo.ErrNoHistory {
NoHistoryErrResponse(w)
return
}
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
Expand Down
8 changes: 4 additions & 4 deletions api/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func (mh *RootHandler) Handler(w http.ResponseWriter, r *http.Request) {
}
res := lib.GetResult{}
err := mh.dsh.Get(&p, &res)
if err == repo.ErrNotFound {
util.NotFoundHandler(w, r)
return
}
if err != nil {
if err == repo.ErrNotFound {
util.NotFoundHandler(w, r)
return
}
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
Expand Down

0 comments on commit 2feb0ab

Please sign in to comment.