From f1171bbe8fd0cfa5be9f43e634c0388e5c11a8b6 Mon Sep 17 00:00:00 2001 From: mohamed Date: Tue, 10 Dec 2024 15:32:50 +0100 Subject: [PATCH] add new EdgeThrottled exception Edge throttles *much* more aggressively than other browsers, added a new ResponseError subclass called EdgeThrottled and added code to verify_response to distinguish this case from a generic ResponseError. I'd still like to know if I ever get throttled by Chrome, Firefox, or Safari since it's never happened before, but it happens so much with Edge that I've just given up and ignore these exceptions personally. Others may want to handle this specific case differently as well. --- lib/web_push/errors.rb | 2 ++ lib/web_push/request.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/web_push/errors.rb b/lib/web_push/errors.rb index e4fa313..2554e8a 100644 --- a/lib/web_push/errors.rb +++ b/lib/web_push/errors.rb @@ -26,4 +26,6 @@ class PayloadTooLarge < ResponseError; end class TooManyRequests < ResponseError; end class PushServiceError < ResponseError; end + + class EdgeThrottled < ResponseError; end end diff --git a/lib/web_push/request.rb b/lib/web_push/request.rb index 7b8780a..71a581d 100644 --- a/lib/web_push/request.rb +++ b/lib/web_push/request.rb @@ -147,6 +147,8 @@ def verify_response(resp) elsif resp.is_a?(Net::HTTPUnauthorized) || resp.is_a?(Net::HTTPForbidden) || # 401, 403 resp.is_a?(Net::HTTPBadRequest) && resp.message == 'UnauthorizedRegistration' # 400, Google FCM raise Unauthorized.new(resp, uri.host) + elsif resp.is_a?(Net::HTTPNotAcceptable) && uri.host.to_s.ends_with?("notify.windows.com") #406 on Edge + raise EdgeThrottled.new(resp, uri.host) elsif resp.is_a?(Net::HTTPRequestEntityTooLarge) # 413 raise PayloadTooLarge.new(resp, uri.host) elsif resp.is_a?(Net::HTTPTooManyRequests) # 429, try again later!