Skip to content

Commit 4a18d2f

Browse files
committed
Updated error handling
1 parent 1500da0 commit 4a18d2f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/monitors/statuscake/statuscake-monitor.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,16 @@ func (service *StatusCakeMonitorService) Setup(p config.Provider) {
225225
// GetByName function will Get a monitor by it's name
226226
func (service *StatusCakeMonitorService) GetByName(name string) (*models.Monitor, error) {
227227
monitors := service.GetAll()
228-
for _, monitor := range monitors {
229-
if monitor.Name == name {
230-
return &monitor, nil
228+
if len(monitors) != 0 {
229+
for _, monitor := range monitors {
230+
if monitor.Name == name {
231+
return &monitor, nil
232+
}
231233
}
232234
}
233235
errorString := "GetByName Request failed for name: " + name
234236
return nil, errors.New(errorString)
237+
235238
}
236239

237240
// GetByID function will Get a monitor by it's ID
@@ -304,6 +307,7 @@ func (service *StatusCakeMonitorService) GetAll() []models.Monitor {
304307
bodyBytes, err := io.ReadAll(resp.Body)
305308
if err != nil {
306309
log.Error(err, "Unable to read response body")
310+
return nil
307311
}
308312

309313
if resp.StatusCode == http.StatusOK {

0 commit comments

Comments
 (0)