weldr: Return a JSON API error response for all unknown requests
This matches the lorax-composer behavior.
This commit is contained in:
parent
e3934108f7
commit
fc205786fc
3 changed files with 10 additions and 5 deletions
|
|
@ -29,10 +29,10 @@ func TestRequest(t *testing.T) {
|
||||||
t.Fatalf("Request bad route: %d != 404", resp.StatusCode)
|
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)
|
_, err = apiError(resp)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
t.Fatalf("apiError of a 404 response did not return an error: %#v", resp)
|
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
|
// Make a request with a bad offset to trigger a JSON response with Status set to 400
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,12 @@ func methodNotAllowedHandler(writer http.ResponseWriter, request *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func notFoundHandler(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) {
|
func notImplementedHandler(writer http.ResponseWriter, httpRequest *http.Request, _ httprouter.Params) {
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ func TestBasic(t *testing.T) {
|
||||||
|
|
||||||
{"/api/v0/projects/source/list", http.StatusOK, `{"sources":["test-id"]}`},
|
{"/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/", 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/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":[]}`},
|
{"/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":[]}`},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue