Skip to content

Commit

Permalink
add new EdgeThrottled exception
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mohamedhafez committed Dec 10, 2024
1 parent 5372677 commit f1171bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/web_push/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ class PayloadTooLarge < ResponseError; end
class TooManyRequests < ResponseError; end

class PushServiceError < ResponseError; end

class EdgeThrottled < ResponseError; end
end
2 changes: 2 additions & 0 deletions lib/web_push/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit f1171bb

Please sign in to comment.