@@ -16,19 +16,37 @@ const WSMessageResponse = z.discriminatedUnion('type', [
16
16
wsExecuteResponseSchema ,
17
17
] ) ;
18
18
19
- const reportWebSocketError = async ( error : string ) => {
20
- try {
21
- await fetch ( '/nowebsocket' , {
22
- method : 'post' ,
23
- headers : {
24
- 'Content-Type' : 'application/json' ,
25
- } ,
26
- body : JSON . stringify ( { error } ) ,
27
- } ) ;
28
- } catch ( reportError ) {
29
- console . log ( 'Unable to report WebSocket error' , error , reportError ) ;
30
- }
31
- } ;
19
+ const reportWebSocketError = ( ( ) => {
20
+ let lastReport : string | undefined ;
21
+ let lastReportTime = 0 ;
22
+
23
+ return async ( error : string ) => {
24
+ // Don't worry about reporting the same thing again.
25
+ if ( lastReport === error ) {
26
+ return ;
27
+ }
28
+ lastReport = error ;
29
+
30
+ // Don't worry about spamming the server with reports.
31
+ const now = Date . now ( ) ;
32
+ if ( now - lastReportTime < 1000 ) {
33
+ return ;
34
+ }
35
+ lastReportTime = now ;
36
+
37
+ try {
38
+ await fetch ( '/nowebsocket' , {
39
+ method : 'post' ,
40
+ headers : {
41
+ 'Content-Type' : 'application/json' ,
42
+ } ,
43
+ body : JSON . stringify ( { error } ) ,
44
+ } ) ;
45
+ } catch ( reportError ) {
46
+ console . log ( 'Unable to report WebSocket error' , error , reportError ) ;
47
+ }
48
+ } ;
49
+ } ) ( ) ;
32
50
33
51
const openWebSocket = ( currentLocation : Location ) => {
34
52
try {
0 commit comments