Answer 500, not 404, when the IP lookup cannot read the database (closes #109)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
A failed database read for an address was listed in the answer's errors as if the address had no route, so the lookup answered 404, or 200 next to a routed address. Only a missing route or an invalid address is listed now; any other read error is logged and answers 500 with the JSON error body, as the AS and prefix JSON routes do. Model: opus-5-5
This commit was merged in pull request #133.
This commit is contained in:
@@ -675,10 +675,7 @@ func (s *Server) handleIPInfo() http.HandlerFunc {
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
response := IPLookupResponse{
|
||||
Query: target,
|
||||
Results: make([]*database.IPInfo, 0),
|
||||
}
|
||||
response := IPLookupResponse{Query: target, Results: make([]*database.IPInfo, 0)}
|
||||
|
||||
// Collect all IPs to look up
|
||||
ipsToLookup, resolveErrors := s.resolveLookupTargets(ctx, target)
|
||||
@@ -708,11 +705,16 @@ func (s *Server) handleIPInfo() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
response.Errors = append(response.Errors,
|
||||
ip+": "+s.lookupErrorMessage(ip, err))
|
||||
switch {
|
||||
case errors.Is(err, database.ErrNoRoute), errors.Is(err, database.ErrInvalidIP):
|
||||
response.Errors = append(response.Errors, ip+": "+err.Error())
|
||||
|
||||
continue
|
||||
case err != nil:
|
||||
s.logger.Error("Failed to look up IP", "ip", ip, "error", err)
|
||||
s.writeJSONError(w, http.StatusInternalServerError, internalErrorMessage)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Do PTR lookup for this IP
|
||||
@@ -751,19 +753,6 @@ func (s *Server) handleIPInfo() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// lookupErrorMessage returns what an IP lookup answer says about err, the
|
||||
// failed lookup of ip: err's own text when ip is not a valid address or has no
|
||||
// route, otherwise a fixed message, with err in the log.
|
||||
func (s *Server) lookupErrorMessage(ip string, err error) string {
|
||||
if errors.Is(err, database.ErrNoRoute) || errors.Is(err, database.ErrInvalidIP) {
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
s.logger.Error("Failed to look up IP", "ip", ip, "error", err)
|
||||
|
||||
return internalErrorMessage
|
||||
}
|
||||
|
||||
// lookupTarget returns what an IP lookup request asks for: the ip or addr URL
|
||||
// parameter, or else the client's own address.
|
||||
func lookupTarget(r *http.Request) string {
|
||||
|
||||
Reference in New Issue
Block a user