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.
This commit is contained in:
n.nakhostin
2025-10-20 11:42:08 +03:30
parent eead4b05d8
commit 7b09291271
+13 -2
View File
@@ -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])