From bf53b2aa38a83fc8228c623075ec36899f2e3e3f Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Sat, 11 Mar 2017 04:48:24 +0100 Subject: [PATCH] commands/dns: return NotFound error for failed resolutions License: MIT Signed-off-by: Lars Gierth --- commands/http/handler.go | 2 ++ commands/response.go | 1 + core/commands/dns.go | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/commands/http/handler.go b/commands/http/handler.go index dd138b98533..ab3d8a56bff 100644 --- a/commands/http/handler.go +++ b/commands/http/handler.go @@ -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 } diff --git a/commands/response.go b/commands/response.go index 913b684bdae..e843f9a0c2c 100644 --- a/commands/response.go +++ b/commands/response.go @@ -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 ) diff --git a/core/commands/dns.go b/core/commands/dns.go index 90ea3678646..099ad6e027c 100644 --- a/core/commands/dns.go +++ b/core/commands/dns.go @@ -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