Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit a236f08

Browse files
authored
Merge pull request #1322 from codysoyland/errors-cause-v0.10
Backport #1304 and #1309 (errors.Cause) to v0.10
2 parents 614fa91 + 59f79fe commit a236f08

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

handler.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (h *Handler) handlePostIndex(w http.ResponseWriter, r *http.Request) {
437437
}
438438

439439
_, err = h.API.CreateIndex(r.Context(), indexName, req.Options)
440-
if err == ErrIndexExists {
440+
if errors.Cause(err) == ErrIndexExists {
441441
http.Error(w, err.Error(), http.StatusConflict)
442442
return
443443
} else if err != nil {
@@ -464,7 +464,7 @@ func (h *Handler) handlePostIndexAttrDiff(w http.ResponseWriter, r *http.Request
464464

465465
attrs, err := h.API.IndexAttrDiff(r.Context(), indexName, req.Blocks)
466466
if err != nil {
467-
if err == ErrIndexNotFound {
467+
if errors.Cause(err) == ErrIndexNotFound {
468468
http.Error(w, err.Error(), http.StatusNotFound)
469469
} else {
470470
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -505,7 +505,7 @@ func (h *Handler) handlePostFrame(w http.ResponseWriter, r *http.Request) {
505505
}
506506
_, err = h.API.CreateFrame(r.Context(), indexName, frameName, req.Options)
507507
if err != nil {
508-
switch err {
508+
switch errors.Cause(err) {
509509
case ErrIndexNotFound:
510510
http.Error(w, err.Error(), http.StatusNotFound)
511511
case ErrFrameExists:
@@ -573,7 +573,7 @@ func (h *Handler) handleDeleteFrame(w http.ResponseWriter, r *http.Request) {
573573

574574
err := h.API.DeleteFrame(r.Context(), indexName, frameName)
575575
if err != nil {
576-
if err == ErrIndexNotFound {
576+
if errors.Cause(err) == ErrIndexNotFound {
577577
if err := json.NewEncoder(w).Encode(deleteIndexResponse{}); err != nil {
578578
h.Logger.Printf("response encoding error: %s", err)
579579
}
@@ -612,7 +612,7 @@ func (h *Handler) handlePostFrameField(w http.ResponseWriter, r *http.Request) {
612612
}
613613

614614
if err := h.API.CreateField(r.Context(), indexName, frameName, field); err != nil {
615-
if err == ErrFrameNotFound {
615+
if errors.Cause(err) == ErrFrameNotFound {
616616
http.Error(w, err.Error(), http.StatusNotFound)
617617
} else {
618618
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -641,7 +641,7 @@ func (h *Handler) handleDeleteFrameField(w http.ResponseWriter, r *http.Request)
641641
fieldName := mux.Vars(r)["field"]
642642

643643
if err := h.API.DeleteField(r.Context(), indexName, frameName, fieldName); err != nil {
644-
if err == ErrFrameNotFound {
644+
if errors.Cause(err) == ErrFrameNotFound {
645645
http.Error(w, err.Error(), http.StatusNotFound)
646646
} else {
647647
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -661,7 +661,7 @@ func (h *Handler) handleGetFrameFields(w http.ResponseWriter, r *http.Request) {
661661

662662
fields, err := h.API.Fields(r.Context(), indexName, frameName)
663663
if err != nil {
664-
switch err {
664+
switch errors.Cause(err) {
665665
case ErrIndexNotFound:
666666
fallthrough
667667
case ErrFrameNotFound:
@@ -691,7 +691,7 @@ func (h *Handler) handleGetFrameViews(w http.ResponseWriter, r *http.Request) {
691691

692692
views, err := h.API.Views(r.Context(), indexName, frameName)
693693
if err != nil {
694-
if err == ErrFrameNotFound {
694+
if errors.Cause(err) == ErrFrameNotFound {
695695
http.Error(w, err.Error(), http.StatusNotFound)
696696
} else {
697697
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -717,7 +717,7 @@ func (h *Handler) handleDeleteView(w http.ResponseWriter, r *http.Request) {
717717
viewName := mux.Vars(r)["view"]
718718

719719
if err := h.API.DeleteView(r.Context(), indexName, frameName, viewName); err != nil {
720-
if err == ErrFrameNotFound {
720+
if errors.Cause(err) == ErrFrameNotFound {
721721
http.Error(w, err.Error(), http.StatusNotFound)
722722
} else {
723723
http.Error(w, err.Error(), http.StatusBadRequest)
@@ -751,7 +751,7 @@ func (h *Handler) handlePostFrameAttrDiff(w http.ResponseWriter, r *http.Request
751751

752752
attrs, err := h.API.FrameAttrDiff(r.Context(), indexName, frameName, req.Blocks)
753753
if err != nil {
754-
switch err {
754+
switch errors.Cause(err) {
755755
case ErrFragmentNotFound:
756756
http.Error(w, err.Error(), http.StatusNotFound)
757757
default:
@@ -878,7 +878,7 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
878878
}
879879

880880
if err := h.API.Import(r.Context(), req); err != nil {
881-
switch err {
881+
switch errors.Cause(err) {
882882
case ErrIndexNotFound:
883883
fallthrough
884884
case ErrFrameNotFound:
@@ -931,7 +931,7 @@ func (h *Handler) handlePostImportValue(w http.ResponseWriter, r *http.Request)
931931
}
932932

933933
if err = h.API.ImportValue(r.Context(), req); err != nil {
934-
switch err {
934+
switch errors.Cause(err) {
935935
case ErrIndexNotFound:
936936
fallthrough
937937
case ErrFrameNotFound:
@@ -980,7 +980,7 @@ func (h *Handler) handleGetExportCSV(w http.ResponseWriter, r *http.Request) {
980980
}
981981

982982
if err = h.API.ExportCSV(r.Context(), index, frame, view, slice, w); err != nil {
983-
switch err {
983+
switch errors.Cause(err) {
984984
case ErrFragmentNotFound:
985985
break
986986
case ErrClusterDoesNotOwnSlice:
@@ -1051,7 +1051,7 @@ func (h *Handler) handlePostFragmentData(w http.ResponseWriter, r *http.Request)
10511051
}
10521052

10531053
if err = h.API.UnmarshalFragment(r.Context(), q.Get("index"), q.Get("frame"), q.Get("view"), slice, r.Body); err != nil {
1054-
if err == ErrFrameNotFound {
1054+
if errors.Cause(err) == ErrFrameNotFound {
10551055
http.Error(w, ErrFrameNotFound.Error(), http.StatusNotFound)
10561056
} else {
10571057
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -1065,7 +1065,7 @@ func (h *Handler) handleGetFragmentBlockData(w http.ResponseWriter, r *http.Requ
10651065
if err != nil {
10661066
if _, ok := err.(BadRequestError); ok {
10671067
http.Error(w, err.Error(), http.StatusBadRequest)
1068-
} else if err == ErrFragmentNotFound {
1068+
} else if errors.Cause(err) == ErrFragmentNotFound {
10691069
http.Error(w, err.Error(), http.StatusNotFound)
10701070
} else {
10711071
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -1091,7 +1091,7 @@ func (h *Handler) handleGetFragmentBlocks(w http.ResponseWriter, r *http.Request
10911091

10921092
blocks, err := h.API.FragmentBlocks(r.Context(), q.Get("index"), q.Get("frame"), q.Get("view"), slice)
10931093
if err != nil {
1094-
if err == ErrFragmentNotFound {
1094+
if errors.Cause(err) == ErrFragmentNotFound {
10951095
http.Error(w, err.Error(), http.StatusNotFound)
10961096
} else {
10971097
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -1131,7 +1131,7 @@ func (h *Handler) handlePostFrameRestore(w http.ResponseWriter, r *http.Request)
11311131
}
11321132

11331133
err = h.API.RestoreFrame(r.Context(), indexName, frameName, host)
1134-
switch err {
1134+
switch errors.Cause(err) {
11351135
case nil:
11361136
break
11371137
case ErrFrameNotFound:

0 commit comments

Comments
 (0)