diff --git a/internal/client/client_test.go b/internal/client/client_test.go index cf51ed710..cf44873a9 100644 --- a/internal/client/client_test.go +++ b/internal/client/client_test.go @@ -29,10 +29,10 @@ func TestRequest(t *testing.T) { t.Fatalf("Request bad route: %d != 404", resp.StatusCode) } - // Test that apiError returns an error when trying to parse non-JSON response + // Test that apiError returns an error response _, err = apiError(resp) - if err == nil { - t.Fatalf("apiError of a 404 response did not return an error: %#v", resp) + if err != nil { + t.Fatalf("apiError could not parse the response: %s", err) } // Make a request with a bad offset to trigger a JSON response with Status set to 400 diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 967d876cf..335dae581 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -167,7 +167,12 @@ func methodNotAllowedHandler(writer http.ResponseWriter, request *http.Request) } func notFoundHandler(writer http.ResponseWriter, request *http.Request) { - writer.WriteHeader(http.StatusNotFound) + errors := responseError{ + Code: http.StatusNotFound, + ID: "HTTPError", + Msg: "Not Found", + } + statusResponseError(writer, http.StatusNotFound, errors) } func notImplementedHandler(writer http.ResponseWriter, httpRequest *http.Request, _ httprouter.Params) { diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index aa8654559..c5c29efbc 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -51,7 +51,7 @@ func TestBasic(t *testing.T) { {"/api/v0/projects/source/list", http.StatusOK, `{"sources":["test-id"]}`}, - {"/api/v0/projects/source/info", http.StatusNotFound, ``}, + {"/api/v0/projects/source/info", http.StatusNotFound, `{"errors":[{"code":404,"id":"HTTPError","msg":"Not Found"}],"status":false}`}, {"/api/v0/projects/source/info/", http.StatusNotFound, `{"errors":[{"code":404,"id":"HTTPError","msg":"Not Found"}],"status":false}`}, {"/api/v0/projects/source/info/foo", http.StatusOK, `{"errors":[{"id":"UnknownSource","msg":"foo is not a valid source"}],"sources":{}}`}, {"/api/v0/projects/source/info/test-id", http.StatusOK, `{"sources":{"test-id":{"name":"test-id","type":"yum-baseurl","url":"http://example.com/test/os/x86_64","check_gpg":true,"check_ssl":true,"system":true}},"errors":[]}`},