Skip to content

Commit f642bd0

Browse files
committed
added missing doc error handling for 404 message
1 parent d53f3e1 commit f642bd0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

api/controllers/astra.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controllers
22

33
import (
44
"context"
5+
"errors"
56
"net/http"
67
"time"
78

@@ -66,8 +67,13 @@ func AstraEventsByBuilding(c *gin.Context) {
6667
// Find astra event given date
6768
err := astraCollection.FindOne(ctx, bson.M{"date": date}).Decode(&astra_events)
6869
if err != nil {
69-
respondWithInternalError(c, err)
70-
return
70+
if errors.Is(err, mongo.ErrNoDocuments) {
71+
astra_events.Date = date
72+
astra_events.Buildings = []schema.SingleBuildingEvents[schema.AstraEvent]{}
73+
} else {
74+
respondWithInternalError(c, err)
75+
return
76+
}
7177
}
7278

7379
//parse response for requested building
@@ -115,8 +121,13 @@ func AstraEventsByBuildingAndRoom(c *gin.Context) {
115121
// Find astra event given date
116122
err := astraCollection.FindOne(ctx, bson.M{"date": date}).Decode(&astra_events)
117123
if err != nil {
118-
respondWithInternalError(c, err)
119-
return
124+
if errors.Is(err, mongo.ErrNoDocuments) {
125+
astra_events.Date = date
126+
astra_events.Buildings = []schema.SingleBuildingEvents[schema.AstraEvent]{}
127+
} else {
128+
respondWithInternalError(c, err)
129+
return
130+
}
120131
}
121132

122133
//parse response for requested building and room

0 commit comments

Comments
 (0)