@@ -209,17 +209,17 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
209209 } else if r .Method == "POST" {
210210 records , err := getProduceRecords (r )
211211 if err != nil {
212- http . Error (w , err . Error () , http .StatusBadRequest )
212+ writeError (w , err , http .StatusBadRequest )
213213 return
214214 }
215215 c := store .NewClient (k .Store , h .app .Monitor .Kafka )
216216 ct := media .ParseContentType (r .Header .Get ("Content-Type" ))
217217 result , err := c .Write (topicName , records , & ct )
218218 if err != nil {
219219 if errors .Is (err , store .TopicNotFound ) || errors .Is (err , store .PartitionNotFound ) {
220- http . Error (w , err . Error () , http .StatusNotFound )
220+ writeError (w , err , http .StatusNotFound )
221221 } else {
222- http . Error (w , err . Error () , http .StatusBadRequest )
222+ writeError (w , err , http .StatusBadRequest )
223223 }
224224 }
225225 res := produceResponse {}
@@ -266,7 +266,7 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
266266 idValue := segments [7 ]
267267 id , err := strconv .Atoi (idValue )
268268 if err != nil {
269- http . Error (w , "error partition ID is not an integer" , http .StatusBadRequest )
269+ writeError (w , fmt . Errorf ( "error partition ID is not an integer" ) , http .StatusBadRequest )
270270 return
271271 }
272272 p := t .Partition (id )
@@ -280,7 +280,7 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
280280 } else {
281281 records , err := getProduceRecords (r )
282282 if err != nil {
283- http . Error (w , err . Error () , http .StatusBadRequest )
283+ writeError (w , err , http .StatusBadRequest )
284284 return
285285 }
286286 for _ , record := range records {
@@ -291,9 +291,9 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
291291 result , err := c .Write (topicName , records , & ct )
292292 if err != nil {
293293 if errors .Is (err , store .TopicNotFound ) || errors .Is (err , store .PartitionNotFound ) {
294- http . Error (w , err . Error () , http .StatusNotFound )
294+ writeError (w , err , http .StatusNotFound )
295295 } else {
296- http . Error (w , err . Error () , http .StatusBadRequest )
296+ writeError (w , err , http .StatusBadRequest )
297297 }
298298 }
299299 res := produceResponse {}
@@ -320,15 +320,15 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
320320 idValue := segments [7 ]
321321 id , err := strconv .Atoi (idValue )
322322 if err != nil {
323- http . Error (w , fmt .Errorf ("error partition ID is not an integer" ). Error ( ), http .StatusBadRequest )
323+ writeError (w , fmt .Errorf ("error partition ID is not an integer" ), http .StatusBadRequest )
324324 return
325325 }
326326 offsetValue := r .URL .Query ().Get ("offset" )
327327 offset := - 1
328328 if offsetValue != "" {
329329 offset , err = strconv .Atoi (offsetValue )
330330 if err != nil {
331- http . Error (w , fmt .Errorf ("error offset is not an integer" ). Error ( ), http .StatusBadRequest )
331+ writeError (w , fmt .Errorf ("error offset is not an integer" ), http .StatusBadRequest )
332332 return
333333 }
334334 }
@@ -338,9 +338,9 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
338338 records , err := c .Read (topicName , id , int64 (offset ), & ct )
339339 if err != nil {
340340 if errors .Is (err , store .TopicNotFound ) || errors .Is (err , store .PartitionNotFound ) {
341- http . Error (w , err . Error () , http .StatusNotFound )
341+ writeError (w , err , http .StatusNotFound )
342342 } else {
343- http . Error (w , err . Error () , http .StatusInternalServerError )
343+ writeError (w , err , http .StatusInternalServerError )
344344 }
345345 return
346346 }
@@ -358,13 +358,13 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
358358 idValue := segments [7 ]
359359 id , err := strconv .Atoi (idValue )
360360 if err != nil {
361- http . Error (w , fmt .Errorf ("error partition ID is not an integer" ). Error ( ), http .StatusBadRequest )
361+ writeError (w , fmt .Errorf ("error partition ID is not an integer" ), http .StatusBadRequest )
362362 return
363363 }
364364 offsetValue := segments [9 ]
365365 offset , err := strconv .Atoi (offsetValue )
366366 if err != nil {
367- http . Error (w , fmt .Errorf ("error offset is not an integer" ). Error ( ), http .StatusBadRequest )
367+ writeError (w , fmt .Errorf ("error offset is not an integer" ), http .StatusBadRequest )
368368 return
369369 }
370370
@@ -373,9 +373,9 @@ func (h *handler) handleKafka(w http.ResponseWriter, r *http.Request) {
373373 records , err := c .Read (topicName , id , int64 (offset ), & ct )
374374 if err != nil {
375375 if errors .Is (err , store .TopicNotFound ) || errors .Is (err , store .PartitionNotFound ) {
376- http . Error (w , err . Error () , http .StatusNotFound )
376+ writeError (w , err , http .StatusNotFound )
377377 } else {
378- http . Error (w , err . Error () , http .StatusBadRequest )
378+ writeError (w , err , http .StatusBadRequest )
379379 }
380380 return
381381 }
0 commit comments