From 9b15d955ff02bf1af88af3aba9cdc1fa30df427d Mon Sep 17 00:00:00 2001 From: j2dm Date: Thu, 10 Oct 2024 14:42:51 +0200 Subject: [PATCH] change server error response, no appended string to avoid malformed json response --- feedapi/server.go | 5 +++-- feedapi/v2_test.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/feedapi/server.go b/feedapi/server.go index 1ecc073..01850ec 100644 --- a/feedapi/server.go +++ b/feedapi/server.go @@ -3,11 +3,12 @@ package feedapi import ( "encoding/json" "fmt" - "github.com/sirupsen/logrus" "net/http" "net/url" "strconv" "strings" + + "github.com/sirupsen/logrus" ) // EventPublisher is a generic-based interface that has to be implemented on a server side. @@ -125,7 +126,7 @@ func (h HTTPHandlers) EventsHandler(writer http.ResponseWriter, request *http.Re if err != nil { logger.WithField("publisherName", h.eventPublisher.GetName()). WithField("event", "feedapi.server.fetch_events_error").WithError(err).Info() - http.Error(writer, "Internal server error", http.StatusInternalServerError) + writer.WriteHeader(http.StatusInternalServerError) return } } diff --git a/feedapi/v2_test.go b/feedapi/v2_test.go index da1dc37..7378ef0 100644 --- a/feedapi/v2_test.go +++ b/feedapi/v2_test.go @@ -2,9 +2,10 @@ package feedapi import ( "context" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func TestAPI_V2_HappyDay_Smoketest(t *testing.T) { @@ -100,7 +101,7 @@ func TestEventsEndpoint(t *testing.T) { token: "the-token", partitionID: 0, cursor: "qwerty", - expectedErrorString: "response code 500, response body: Internal server error\n", + expectedErrorString: "response code 500, empty response body", }, { name: "out of range cursor",