Skip to content

Commit

Permalink
Handle error in folders/files
Browse files Browse the repository at this point in the history
  • Loading branch information
smoyte committed Feb 26, 2024
1 parent d70cbe2 commit 6d413d7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/models/gdrive/item_syncer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def sync
end
else
service.get_file(item.external_id, fields: "name,mimeType,capabilities(canShare)", supports_all_drives: true) do |result, error|
item.kind = (result.mime_type == GDrive::FOLDER_MIME_TYPE) ? "folder" : "file"
process_item(item, result, error)
end
end
Expand All @@ -35,11 +34,16 @@ def process_item(item, result, error)
if error
Rails.logger.error("Error accessing item", item_id: item.id, error: error.to_s)
item.update!(error_type: "inaccessible")
elsif !result.capabilities.can_share
item.update!(name: result.name, error_type: "not_shareable")
else
item.update!(name: result.name, error_type: nil)
return
end

# Drives use a separate API endpoint so if the type were wrong it would have errored above.
unless item.drive?
item.kind = (result.mime_type == GDrive::FOLDER_MIME_TYPE) ? "folder" : "file"
end
item.name = result.name
item.error_type = result.capabilities.can_share ? nil : "not_shareable"
item.save!
end
end
end

0 comments on commit 6d413d7

Please sign in to comment.