Skip to content

Commit 44f8d9c

Browse files
Added new type
1 parent da89356 commit 44f8d9c

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

internal/session/handler.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ func (m *Manager) IssueTransaction(w http.ResponseWriter, r *http.Request) {
7878
}
7979

8080
type handlerCtxKey string
81+
type handlerType string
82+
83+
const (
84+
HandlerType handlerType = "type"
85+
)
8186

8287
const (
8388
CtxStreamUserSession handlerCtxKey = "stream_user_session"
@@ -143,7 +148,7 @@ func (m *Manager) StreamUserSession(w http.ResponseWriter, r *http.Request) {
143148
go m.listenForSessionChanges(ctx, conn, sessionID)
144149

145150
/* specify the handler context */
146-
ctxVal := context.WithValue(ctx, "type", CtxStreamUserSession)
151+
ctxVal := context.WithValue(ctx, HandlerType, CtxStreamUserSession)
147152

148153
/* handle web socket instructions from client */
149154
m.handleWebSocketCommands(conn, username, sessionID, ctxVal, cancel)
@@ -205,7 +210,7 @@ func (m *Manager) StreamUserTransactionsResults(w http.ResponseWriter, r *http.R
205210
go m.listenForTransactionsChangesResults(ctx, conn, sessionID)
206211

207212
/* specify the handler context */
208-
ctxVal := context.WithValue(ctx, "type", CtxStreamUserTransactionsResults)
213+
ctxVal := context.WithValue(ctx, HandlerType, CtxStreamUserTransactionsResults)
209214

210215
/* handle web socket instructions from client */
211216
m.handleWebSocketCommands(conn, username, sessionID, ctxVal, cancel)
@@ -267,7 +272,7 @@ func (m *Manager) StreamUserTransactionsPending(w http.ResponseWriter, r *http.R
267272
go m.listenForTransactionsChangesPending(ctx, conn, sessionID)
268273

269274
/* specify the handler context */
270-
ctxVal := context.WithValue(ctx, "type", CtxStreamUserTransactionsPending)
275+
ctxVal := context.WithValue(ctx, HandlerType, CtxStreamUserTransactionsPending)
271276

272277
/* handle web socket instructions from client */
273278
m.handleWebSocketCommands(conn, username, sessionID, ctxVal, cancel)
@@ -336,7 +341,10 @@ func (m *Manager) StreamUserArchiveSessions(w http.ResponseWriter, r *http.Reque
336341

337342
/* send response with json */
338343
w.Header().Set("Content-Type", "application/json")
339-
json.NewEncoder(w).Encode(sessions)
344+
if err := json.NewEncoder(w).Encode(sessions); err != nil {
345+
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
346+
return
347+
}
340348
}
341349

342350
/*
@@ -402,7 +410,10 @@ func (m *Manager) StreamUserArchiveResultsTransactions(w http.ResponseWriter, r
402410

403411
/* send response with json */
404412
w.Header().Set("Content-Type", "application/json")
405-
json.NewEncoder(w).Encode(sessions)
413+
if err := json.NewEncoder(w).Encode(sessions); err != nil {
414+
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
415+
return
416+
}
406417
}
407418

408419
/*
@@ -468,5 +479,8 @@ func (m *Manager) StreamUserArchivePendingTransactions(w http.ResponseWriter, r
468479

469480
/* send response with json */
470481
w.Header().Set("Content-Type", "application/json")
471-
json.NewEncoder(w).Encode(sessions)
482+
if err := json.NewEncoder(w).Encode(sessions); err != nil {
483+
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
484+
return
485+
}
472486
}

0 commit comments

Comments
 (0)