Google Calendar V3 insert_calendar API returns 503, but calendar was inserted successfully

I have a problem when I send an insert_calendar request to the Google Calendar API V3 and I return the following response:

 Sending HTTP post https://www.googleapis.com/calendar/v3/calendars? 503 #<HTTP::Message:0x000000124eb008 @http_header=#<HTTP::Message::Headers:0x000000124eafe0 @http_version="1.1", @body_size=0, @chunked=false, @request_method="POST", @request_uri=#<Addressable::URI:0x9275f20 URI:https://www.googleapis.com/calendar/v3/calendars?>, @request_query=nil, @request_absolute_uri=nil, @status_code=503, @reason_phrase="Service Unavailable", @body_type=nil, @body_charset=nil, @body_date=nil, @body_encoding=#<Encoding:UTF-8>, @is_request=false, @header_item=[ ["Vary", "Origin"], ["Vary", "X-Origin"], ["Content-Type", "application/json; charset=UTF-8"], ["Content-Encoding", "gzip"], ["Date", "Fri, 25 Aug 2017 20:16:34 GMT"], ["Expires", "Fri, 25 Aug 2017 20:16:34 GMT"], ["Cache-Control", "private, max-age=0"], ["X-Content-Type-Options", "nosniff"], ["X-Frame-Options", "SAMEORIGIN"], ["X-XSS-Protection", "1; mode=block"], ["Server", "GSE"], ["Alt-Svc", "quic=\":443\"; ma=2592000; v=\"39,38,37,35\""], ["Transfer-Encoding", "chunked"] ], @dumped=false>, @peer_cert=#<OpenSSL::X509::Certificate: subject=#<OpenSSL::X509::Name:0x00000012600998>, issuer=#<OpenSSL::X509::Name:0x000000126009c0>, serial=#<OpenSSL::BN:0x000000126009e8>, not_before=2017-08-15 16:06:52 UTC, not_after=2017-11-07 16:04:00 UTC >, @http_body=#<HTTP::Message::Body:0x000000124eaf68 @body="{\n \"error\": {\n \"errors\": [\n{\n \"domain\": \"global\",\n \"reason\": \"backendError\",\n \"message\": \"Backend Error\"\n }\n ],\n \"code\": 503,\n \"message\": \"Backend Error\"\n }\n}\n", @size=0, @positions=nil, @chunk_size=nil >, @previous=nil> Caught error Server error Error - #<Google::Apis::ServerError: Server error> 

I am using the Google Ruby Client API, here:

 google-api-client (0.13.1) addressable (~> 2.5, >= 2.5.1) googleauth (~> 0.5) httpclient (>= 2.8.1, < 3.0) mime-types (~> 3.0) representable (~> 3.0) retriable (>= 2.0, < 4.0) 

The problem I encountered is not related to the error, but the calendar has been inserted successfully.

As you can see from the answer, I am not getting anything, which says that it was successful, despite 503 , for example, the Google Calendar ID.

The influence this has on my application is that I don’t know what I successfully synchronized, and in fact, following the documents, I implement exponential delay, so I continue to create duplicate calendars in Google calendars for my users.

In the end, I have a bunch of orphan calendars showing what I should delete with string matching.

Is this expected? Is there anything I can do to mitigate this?

This happens with regularity and is not an isolated case.


The code in question:

 def handle_calendar_response(response, error) self.update_column('last_synced_at', Time.now.utc) if error.present? Airbrake.notify('Sync Calendar Sync Error', { error: error, message: error.message, calendar: self }) # String match :( if error.message =~ /not.?found/i || error.message =~ /forbidden/i Airbrake.notify('Removing user deleted calendar', { calendar: self, google_calendar_id: self.google_calendar_id, error: error, message: error.message }) self.publish_to_google = false self.google_calendar_id = nil self.save! end end end ... def insert_calendar @client.insert_calendar(google_calendar_object) do |response, error| handle_calendar_response(response, error) if response.present? self.google_calendar_id = response.id self.save! end end end 

These are the methods from the synchronized calendar view in our data model. You can call insert_calendar to insert it. We always take the same action in response from Google, if we insert, update or delete, we always call handle_calendar_response .

+5
source share
1 answer

Since the errors are in the google backend system, in fact you cannot make it so that you can correct it on your side in the direction of reporting the error. However, you can handle this on your side by adding your own identifier and placing it in the private advanced properties of the calendar that you want to create. The identifier can be something like a combination of the date / time and the subject of the event, or even a random UIID, as long as you guarantee that it is unique. Then, before issuing another request, when you receive an error, first go through the users calendars and check if there is an event with an identifier on the same date. This assumes that you have read permissions for user calendars. Hope this helps.

+1
source

Source: https://habr.com/ru/post/1271244/


All Articles