Skip to content

Commit

Permalink
commands/dns: return NotFound error for failed resolutions
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Lars Gierth <[email protected]>
  • Loading branch information
Lars Gierth committed Mar 11, 2017
1 parent 3ebb662 commit bf53b2a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions commands/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
if e := res.Error(); e != nil {
if e.Code == cmds.ErrClient {
status = http.StatusBadRequest
} else if e.Code == cmds.ErrNotFound {
status = http.StatusNotFound
} else {
status = http.StatusInternalServerError
}
Expand Down
1 change: 1 addition & 0 deletions commands/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ErrorType uint
const (
ErrNormal ErrorType = iota // general errors
ErrClient // error was caused by the client, (e.g. invalid CLI usage)
ErrNotFound // == HTTP 404 Not Found
ErrImplementation // programmer error in the server
// TODO: add more types of errors for better error-specific handling
)
Expand Down
4 changes: 4 additions & 0 deletions core/commands/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ The resolver can recursively resolve:
depth = namesys.DefaultDepthLimit
}
output, err := resolver.ResolveN(req.Context(), name, depth)
if err == namesys.ErrResolveFailed {
res.SetError(err, cmds.ErrNotFound)
return
}
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
Expand Down

0 comments on commit bf53b2a

Please sign in to comment.