diff --git a/fakestorage/json_response.go b/fakestorage/json_response.go index f16a7c5c10..99e8ce7d4c 100644 --- a/fakestorage/json_response.go +++ b/fakestorage/json_response.go @@ -32,7 +32,7 @@ func jsonToHTTPHandler(h jsonHandler) http.HandlerFunc { status := resp.getStatus() var data any if status > 399 { - data = newErrorResponse(status, resp.getErrorMessage(status), nil) + data = newErrorResponse(status, resp.getErrorMessage(status), resp.getErrorList(status)) } else { data = resp.data } @@ -59,6 +59,18 @@ func (r *jsonResponse) getErrorMessage(status int) string { return http.StatusText(status) } +func (r *jsonResponse) getErrorList(status int) []apiError { + if status == http.StatusOK { + return nil + } else { + return []apiError{{ + Domain: "global", + Reason: http.StatusText(status), + Message: r.getErrorMessage(status), + }} + } +} + func errToJsonResponse(err error) jsonResponse { status := 0 var pathError *os.PathError diff --git a/fakestorage/object_test.go b/fakestorage/object_test.go index b1581583ed..1c11a3190f 100644 --- a/fakestorage/object_test.go +++ b/fakestorage/object_test.go @@ -2028,7 +2028,7 @@ func TestServiceClientComposeObject(t *testing.T) { "files/destination.txt", []string{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33"}, "", - "googleapi: Error 400: The number of source components provided (33) exceeds the maximum (32)", + "googleapi: Error 400: The number of source components provided (33) exceeds the maximum (32), Bad Request", }, } for _, test := range tests { diff --git a/fakestorage/upload_test.go b/fakestorage/upload_test.go index 79908fa42d..582c913e35 100644 --- a/fakestorage/upload_test.go +++ b/fakestorage/upload_test.go @@ -224,7 +224,7 @@ func TestServerClientObjectWriterWithDoesNotExistPrecondition(t *testing.T) { if err == nil { t.Fatal("expected overwriting existing object to fail, but received no error") } - if err.Error() != "googleapi: Error 412: Precondition failed" { + if err.Error() != "googleapi: Error 412: Precondition failed, Precondition Failed" { t.Errorf("expected HTTP 412 precondition failed error, but got %v", err) } @@ -346,7 +346,7 @@ func TestServerClientObjectOperationsWithIfGenerationNotMatchPrecondition(t *tes if err == nil { t.Fatal("expected overwriting existing object to fail, but received no error") } - if err.Error() != "googleapi: Error 412: Precondition failed" { + if err.Error() != "googleapi: Error 412: Precondition failed, Precondition Failed" { t.Errorf("expected HTTP 412 precondition failed error, but got %v", err) }