Skip to content

Commit

Permalink
gateway: use switch for error handling
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
  • Loading branch information
Kubuxu committed Sep 12, 2016
1 parent 51e55d7 commit bba2a85
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,24 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
}

nd, err := core.Resolve(ctx, i.node, path.Path(urlPath))
// If node is in offline mode the error code and message should be different
if err == core.ErrNoNamesys && !i.node.OnlineMode() {
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprint(w, "Could not resolve path. Node is in offline mode.")
return
} else if err == namesys.ErrResolveFailed {
switch err {
case nil:
// core.Resolve worked
case namesys.ErrResolveFailed:
// Don't log that error as it is just noise
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "Path Resolve error: %s", err.Error())
log.Info("Path Resolve error: %s", err.Error())
return
} else if err != nil {
case core.ErrNoNamesys:
if !i.node.OnlineMode() {
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprint(w, "Could not resolve path. Node is in offline mode.")
return
}
fallthrough
default:
// all other erros
webError(w, "Path Resolve error", err, http.StatusBadRequest)
return
}
Expand Down

0 comments on commit bba2a85

Please sign in to comment.