From c4a4b3395f0df2ee7ce9152f3e9ad063254eaaff Mon Sep 17 00:00:00 2001 From: mohit-nagaraj Date: Sat, 19 Oct 2024 20:09:58 +0530 Subject: [PATCH] Fix errors --- controllers/file_controller.go | 6 +++++- services/file_service.go | 6 +++++- utils/helpers/helpers.go | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/controllers/file_controller.go b/controllers/file_controller.go index 3658dae..c762e83 100644 --- a/controllers/file_controller.go +++ b/controllers/file_controller.go @@ -100,6 +100,10 @@ func (f *fileController) ParseXLSXFile(ctx *gin.Context) { } span.Status = sentry.SpanStatusOK - ctx.Writer.Write([]byte("\nStream complete.\n")) + if _, err := ctx.Writer.Write([]byte("\nStream complete.\n")); err != nil { + ctx.JSON(500, gin.H{"error": "Error streaming"}) + return + } + ctx.Writer.Flush() // Ensure the final response is sent } diff --git a/services/file_service.go b/services/file_service.go index fb20aa5..72ed813 100644 --- a/services/file_service.go +++ b/services/file_service.go @@ -64,7 +64,11 @@ func (fs *fileService) ParseXLSXFile(ctx *gin.Context, files <-chan string) erro zap.L().Info("File uploaded to Cloudinary", zap.String("filePath", filePath), zap.String("url", uploadResult.SecureURL)) // Create a new reader from the uploaded file - file.Seek(0, 0) + if _, err := file.Seek(0, 0); err != nil { + zap.L().Error("Error seeking file", zap.String("filePath", filePath), zap.Error(err)) + return err + } + f, err := excelize.OpenReader(file) if err != nil { zap.L().Error("Error parsing XLSX file", zap.String("filePath", filePath), zap.Error(err)) diff --git a/utils/helpers/helpers.go b/utils/helpers/helpers.go index 1adbf0a..a63608e 100644 --- a/utils/helpers/helpers.go +++ b/utils/helpers/helpers.go @@ -3,7 +3,7 @@ package helpers import ( "errors" "fmt" - "io/ioutil" + "io" "math" "net/http" "os" @@ -379,7 +379,7 @@ func FetchPeerData(dataWarehouseID string) ([]map[string]string, error) { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - bodyBytes, _ := ioutil.ReadAll(resp.Body) + bodyBytes, _ := io.ReadAll(resp.Body) bodyString := string(bodyBytes) zap.L().Error("Received non-200 response code", zap.Int("status_code", resp.StatusCode), zap.String("body", bodyString)) return nil, fmt.Errorf("received non-200 response code from peers API: %d", resp.StatusCode)