Skip to content

Commit

Permalink
fix: Check response size before accessing
Browse files Browse the repository at this point in the history
* Null response will result in runtime error. Check if len is more than zero before accessing

Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Dec 26, 2023
1 parent 839b12e commit c3ff933
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/emissions/rte.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,9 @@ func makeRTEAPIRequest(ctx context.Context, logger log.Logger) (float64, error)

var fields []nationalRealTimeFieldsV2
fields = append(fields, data.Results...)
return float64(fields[0].TauxCo2), nil
// Check size of fields as it can be zero sometimes
if len(fields) >= 1 {
return float64(fields[0].TauxCo2), nil
}
return -1, fmt.Errorf("Null response received from RTE server: %v", fields)
}

0 comments on commit c3ff933

Please sign in to comment.