From 7b0929127120f3357f7c300db1e230c70d0c9f2c Mon Sep 17 00:00:00 2001 From: "n.nakhostin" Date: Mon, 20 Oct 2025 11:42:08 +0330 Subject: [PATCH] Improve Error Handling in GetOJS Function - Enhanced the GetOJS function to include error handling for reading the response body and parsing CSV records, ensuring that errors are properly returned instead of being ignored. - Added a check to ensure that the CSV records contain data, returning a meaningful error if the calendar is empty, which improves robustness and clarity in error reporting. --- ted/calendar.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ted/calendar.go b/ted/calendar.go index dc413b9..0c4cc4a 100644 --- a/ted/calendar.go +++ b/ted/calendar.go @@ -27,9 +27,20 @@ func GetOJS(baseURL string, year int, date string) (string, error) { defer resp.Body.Close() // read CSV - body, _ := io.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) + if err != nil { + return ojs, err + } + reader := csv.NewReader(bytes.NewReader(body)) - records, _ := reader.ReadAll() + records, err := reader.ReadAll() + if err != nil { + return ojs, err + } + + if len(records) < 2 { + return ojs, fmt.Errorf("ojs calendar is empty") + } for _, row := range records[1:] { rowDate := strings.TrimSpace(row[1])