better error handling

This commit is contained in:
2022-06-03 14:27:40 +02:00
parent 2be2cc0626
commit 2f5cd563ad
5 changed files with 27 additions and 3 deletions

View File

@@ -117,6 +117,10 @@ func CreateRouter(client *client.Client, username, password string) *mux.Router
share, err := client.CreateShare(r.Context(), shareParams.Key)
if err != nil {
if err == types.ErrKeyNotFound {
http.Error(w, "The specified key does not exist", http.StatusBadRequest)
return
}
logrus.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -136,6 +140,10 @@ func CreateRouter(client *client.Client, username, password string) *mux.Router
err := client.DeleteShare(r.Context(), vars["slug"])
if err != nil {
if err == types.ErrShareNotFound {
http.NotFound(w, r)
return
}
logrus.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return