mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 02:57:57 +00:00 
			
		
		
		
	chore: Handle WebPush rate limiting in push notification service (#12184)
Implemented a rescue block for WebPush::TooManyRequests that logs warnings during rate limiting events. This captures user email and account ID for better traceability. We will implement a proper throttling mechanism after identifying patterns across accounts.
This commit is contained in:
		| @@ -68,14 +68,23 @@ class Notification::PushNotificationService | |||||||
|  |  | ||||||
|     WebPush.payload_send(**browser_push_payload(subscription)) |     WebPush.payload_send(**browser_push_payload(subscription)) | ||||||
|     Rails.logger.info("Browser push sent to #{user.email} with title #{push_message[:title]}") |     Rails.logger.info("Browser push sent to #{user.email} with title #{push_message[:title]}") | ||||||
|   rescue WebPush::ExpiredSubscription, WebPush::InvalidSubscription, WebPush::Unauthorized => e |  | ||||||
|     Rails.logger.info "WebPush subscription expired: #{e.message}" |  | ||||||
|     subscription.destroy! |  | ||||||
|   rescue Errno::ECONNRESET, Net::OpenTimeout, Net::ReadTimeout => e |  | ||||||
|     Rails.logger.error "WebPush operation error: #{e.message}" |  | ||||||
|   rescue StandardError => e |   rescue StandardError => e | ||||||
|     ChatwootExceptionTracker.new(e, account: notification.account).capture_exception |     handle_browser_push_error(e, subscription) | ||||||
|     true |   end | ||||||
|  |  | ||||||
|  |   def handle_browser_push_error(error, subscription) | ||||||
|  |     case error | ||||||
|  |     when WebPush::ExpiredSubscription, WebPush::InvalidSubscription, WebPush::Unauthorized | ||||||
|  |       Rails.logger.info "WebPush subscription expired: #{error.message}" | ||||||
|  |       subscription.destroy! | ||||||
|  |     when WebPush::TooManyRequests | ||||||
|  |       Rails.logger.warn "WebPush rate limited for #{user.email} on account #{notification.account.id}: #{error.message}" | ||||||
|  |     when Errno::ECONNRESET, Net::OpenTimeout, Net::ReadTimeout | ||||||
|  |       Rails.logger.error "WebPush operation error: #{error.message}" | ||||||
|  |     else | ||||||
|  |       ChatwootExceptionTracker.new(error, account: notification.account).capture_exception | ||||||
|  |       true | ||||||
|  |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   def send_fcm_push(subscription) |   def send_fcm_push(subscription) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Muhsin Keloth
					Muhsin Keloth