From 7873126720ff6b125796b56e44cc1c40cb74a831 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Thu, 5 Jul 2018 18:39:25 -0500 Subject: [PATCH] handle errors a bit better in handlePostQuery --- http/handler.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/http/handler.go b/http/handler.go index 7786eb2f3..8cc52a9b9 100644 --- a/http/handler.go +++ b/http/handler.go @@ -412,18 +412,25 @@ func (h *Handler) handlePostQuery(w http.ResponseWriter, r *http.Request) { resp, err := h.API.Query(r.Context(), req) if err != nil { - w.WriteHeader(http.StatusBadRequest) + switch errors.Cause(resp.Err) { + case pilosa.ErrTooManyWrites: + w.WriteHeader(http.StatusRequestEntityTooLarge) + default: + w.WriteHeader(http.StatusBadRequest) + } h.writeQueryResponse(w, r, &pilosa.QueryResponse{Err: err}) return } - // Set appropriate status code, if there is an error. + // Set appropriate status code, if there is an error. It doesn't appear that + // resp.Err could ever be set in API.Query, so this code block is probably + // doing nothing right now. if resp.Err != nil { - switch resp.Err { + switch errors.Cause(resp.Err) { case pilosa.ErrTooManyWrites: w.WriteHeader(http.StatusRequestEntityTooLarge) default: - w.WriteHeader(http.StatusInternalServerError) + w.WriteHeader(http.StatusBadRequest) } }