Skip to content

Commit 54f4271

Browse files
committed
Added 410 Gone responses to EventSub WebSocket server when trying to subscribe to an event version that was removed
1 parent f7e353f commit 54f4271

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

internal/events/types/types.go

+8
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,11 @@ func GetByTriggerAndTransportAndVersion(trigger string, transport string, versio
151151
// Default error
152152
return nil, errors.New("Invalid event")
153153
}
154+
155+
// These events were removed from production
156+
// This does not include any "beta" events, just old production versions
157+
func RemovedEvents() map[string]string {
158+
return map[string]string{
159+
"channel.follow": "1",
160+
}
161+
}

internal/events/websocket/mock_server/manager.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,14 @@ func subscriptionPageHandlerPost(w http.ResponseWriter, r *http.Request) {
337337
return
338338
}
339339

340-
// Check if the topic exists
340+
// Check if the topic was deprecated/removed
341+
for e, v := range types.RemovedEvents() {
342+
if body.Type == e && body.Version == v {
343+
handlerResponseErrorGone(w)
344+
return
345+
}
346+
}
347+
341348
_, err = types.GetByTriggerAndTransportAndVersion(body.Type, body.Transport.Method, body.Version)
342349
if err != nil {
343350
handlerResponseErrorBadRequest(w, "The combination of values in the type and version fields is not valid")
@@ -546,3 +553,13 @@ func handlerResponseErrorInternalServerError(w http.ResponseWriter, message stri
546553
})
547554
w.Write(bytes)
548555
}
556+
557+
func handlerResponseErrorGone(w http.ResponseWriter) {
558+
w.WriteHeader(http.StatusGone)
559+
bytes, _ := json.Marshal(&SubscriptionPostErrorResponse{
560+
Error: "Gone",
561+
Message: "This subscription type is not available.",
562+
Status: 410,
563+
})
564+
w.Write(bytes)
565+
}

0 commit comments

Comments
 (0)