Skip to content

Commit aebe773

Browse files
authored
Merge pull request #129 from dedis/proxy-errors
Fixes error handling on the proxy
2 parents 65af10d + f93670b commit aebe773

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

proxy/dkg.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (d dkg) Actor(w http.ResponseWriter, r *http.Request) {
8585

8686
actor, found := d.d.GetActor(electionIDBuf)
8787
if !found {
88-
BadRequestError(w, r, xerrors.New("actor not found"), nil)
88+
NotFoundErr(w, r, xerrors.New("actor not found"), nil)
8989
return
9090
}
9191

@@ -168,5 +168,8 @@ func (d dkg) EditDKGActor(w http.ResponseWriter, r *http.Request) {
168168
http.Error(w, "failed to compute pubshares: "+err.Error(), http.StatusInternalServerError)
169169
return
170170
}
171+
default:
172+
BadRequestError(w, r, xerrors.Errorf("invalid action: %s", req.Action), nil)
173+
return
171174
}
172175
}

proxy/election.go

+3
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ func (h *election) EditElection(w http.ResponseWriter, r *http.Request) {
243243
h.combineShares(electionID, w, r)
244244
case "cancel":
245245
h.cancelElection(electionID, w, r)
246+
default:
247+
BadRequestError(w, r, xerrors.Errorf("invalid action: %s", req.Action), nil)
248+
return
246249
}
247250
}
248251

proxy/mod.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ func ForbiddenError(w http.ResponseWriter, r *http.Request, err error, args map[
107107
httpErr(w, r, err, http.StatusForbidden, "not authorized / forbidden", args)
108108
}
109109

110+
// NotFoundErr sets a not found error
111+
func NotFoundErr(w http.ResponseWriter, r *http.Request, err error, args map[string]interface{}) {
112+
httpErr(w, r, err, http.StatusNotFound, "not found", args)
113+
}
114+
110115
func httpErr(w http.ResponseWriter, r *http.Request, err error, code uint, title string, args map[string]interface{}) {
111116
if args == nil {
112117
args = make(map[string]interface{})
@@ -127,7 +132,7 @@ func httpErr(w http.ResponseWriter, r *http.Request, err error, code uint, title
127132

128133
w.Header().Set("Content-Type", "application/json; charset=utf-8")
129134
w.Header().Set("X-Content-Type-Options", "nosniff")
130-
w.WriteHeader(http.StatusInternalServerError)
135+
w.WriteHeader(int(code))
131136
fmt.Fprintln(w, string(buf))
132137
}
133138

proxy/shuffle.go

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
shuffleSrv "github.com/dedis/d-voting/services/shuffle"
1010
"github.com/gorilla/mux"
1111
"go.dedis.ch/kyber/v3"
12+
"golang.org/x/xerrors"
1213
)
1314

1415
// NewShuffle returns a new initialized shuffle
@@ -65,5 +66,8 @@ func (s shuffle) EditShuffle(w http.ResponseWriter, r *http.Request) {
6566
http.Error(w, "failed to shuffle: "+err.Error(), http.StatusInternalServerError)
6667
return
6768
}
69+
default:
70+
BadRequestError(w, r, xerrors.Errorf("invalid action: %s", req.Action), nil)
71+
return
6872
}
6973
}

runNode.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tmux list-sessions | rg "^$s:" >/dev/null 2>&1 && { echo >&2 "A session with the
1616

1717
tmux new-session -d -s $s
1818

19+
make build
1920

2021
from=1
2122
to=$1
@@ -25,7 +26,7 @@ do
2526
echo $from
2627
tmux new-window -t $s
2728
window=$from
28-
tmux send-keys -t $s:$window "LLVL=info ./memcoin --config /tmp/node$from start --postinstall --promaddr :$((9099 + $from)) --proxyaddr :$((9079 + $from)) --proxykey $pk --listen tcp://0.0.0.0:$((2000 + $from)) --public //localhost:$((2000 + $from))" C-m
29+
tmux send-keys -t $s:$window "PROXY_LOG=info LLVL=info ./memcoin --config /tmp/node$from start --postinstall --promaddr :$((9099 + $from)) --proxyaddr :$((9079 + $from)) --proxykey $pk --listen tcp://0.0.0.0:$((2000 + $from)) --public //localhost:$((2000 + $from))" C-m
2930
((from++))
3031

3132
done

0 commit comments

Comments
 (0)