diff --git a/src/database/pocketbase.go b/src/database/pocketbase.go index 0b58817..c360d1e 100644 --- a/src/database/pocketbase.go +++ b/src/database/pocketbase.go @@ -70,20 +70,24 @@ func (p *PbClient) GetServiceByNameOrUrl(id string) (*Service, error) { return nil, err } - service := response.Items[0] + if len(response.Items) > 0 { + service := response.Items[0] - // Sort attributes by rating - sort.SliceStable(service.Expand["attributes"], func(i, j int) bool { - ratingOrder := map[string]int{ - "bad": 4, - "warn": 3, - "good": 2, - "info": 1, - } - return ratingOrder[service.Expand["attributes"][i].Rating] > ratingOrder[service.Expand["attributes"][j].Rating] - }) + // Sort attributes by rating + sort.SliceStable(service.Expand["attributes"], func(i, j int) bool { + ratingOrder := map[string]int{ + "bad": 4, + "warn": 3, + "good": 2, + "info": 1, + } + return ratingOrder[service.Expand["attributes"][i].Rating] > ratingOrder[service.Expand["attributes"][j].Rating] + }) + return &service, nil + } else { + return nil, fmt.Errorf("Service not found.") + } - return &service, nil } func (p *PbClient) GetServiceById(id string) (*Service, error) {