Skip to content

Commit

Permalink
Futher additions for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Fearne committed Aug 11, 2022
1 parent 7e222b4 commit 7d13f7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 8 additions & 5 deletions internal/http/services/cback/cback.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func (s *svc) handleRestoreID(w http.ResponseWriter, r *http.Request) {

resp, err := s.matchBackups(user.Username, path)

if resp == nil {
http.Error(w, errtypes.NotFound("cback: not found").Error(), http.StatusInternalServerError)
return
}

if err != nil {
fmt.Print(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand All @@ -141,14 +146,14 @@ func (s *svc) handleRestoreID(w http.ResponseWriter, r *http.Request) {
requestType := "POST"

if ssID == "" {
http.Error(w, errtypes.NotFound("cback: snapshot not found").Error(), http.StatusInternalServerError)
http.Error(w, errtypes.NotFound("cback: snapshot not found").Error(), http.StatusNotFound)
return
}

err = s.statResource(resp.ID, ssID, user.Username, searchPath, resp.Source)

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), http.StatusNotFound)
return
}

Expand Down Expand Up @@ -187,7 +192,7 @@ func (s *svc) handleRestoreID(w http.ResponseWriter, r *http.Request) {
} else {

err = errtypes.NotFound("cback: resource not found")
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), http.StatusNotFound)
return
}
}
Expand Down Expand Up @@ -289,8 +294,6 @@ func (s *svc) Request(userName, url string, reqType string, body io.Reader) (io.

func (s *svc) Handler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

s.router.ServeHTTP(w, r)

})
}
1 change: 0 additions & 1 deletion internal/http/services/cback/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,4 @@ func (s *svc) statResource(backupID int, snapID, userName, path, source string)
defer responseData.Close()

return nil

}

0 comments on commit 7d13f7b

Please sign in to comment.