Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mohit-nagaraj committed Oct 19, 2024
1 parent a06f1bb commit c4a4b33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion controllers/file_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion services/file_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions utils/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package helpers
import (
"errors"
"fmt"
"io/ioutil"
"io"
"math"
"net/http"
"os"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c4a4b33

Please sign in to comment.