@@ -56,7 +56,7 @@ def self.run(params)
5656
5757 binary_type = binary_type_from_path ( binary_path )
5858 UI . message ( "📡 Uploading the #{ binary_type } ." )
59- operation = upload_binary ( app_name , binary_path , client , timeout )
59+ operation = upload_binary ( app_name , binary_path , binary_type , client , timeout )
6060 UI . message ( "🕵️ Validating upload…" )
6161 release = poll_upload_release_operation ( client , operation , binary_type )
6262
@@ -268,7 +268,7 @@ def self.poll_upload_release_operation(client, operation, binary_type)
268268 extract_release ( operation )
269269 end
270270
271- def self . upload_binary ( app_name , binary_path , client , timeout )
271+ def self . upload_binary ( app_name , binary_path , binary_type , client , timeout )
272272 options = Google ::Apis ::RequestOptions . new
273273 options . max_elapsed_time = timeout # includes retries (default = no retries)
274274 options . header = {
@@ -282,12 +282,21 @@ def self.upload_binary(app_name, binary_path, client, timeout)
282282 # standard http call instead and convert it to a long running object
283283 # https://github.com/googleapis/google-api-ruby-client/blob/main/generated/google-apis-firebaseappdistribution_v1/lib/google/apis/firebaseappdistribution_v1/service.rb#L79
284284 # TODO(kbolay): Prefer client.upload_medium
285- response = client . http (
286- :post ,
287- "https://firebaseappdistribution.googleapis.com/upload/v1/#{ app_name } /releases:upload" ,
288- body : File . open ( binary_path , 'rb' ) ,
289- options : options
290- )
285+ response = begin
286+ client . http (
287+ :post ,
288+ "https://firebaseappdistribution.googleapis.com/upload/v1/#{ app_name } /releases:upload" ,
289+ body : File . open ( binary_path , 'rb' ) ,
290+ options : options
291+ )
292+ rescue Google ::Apis ::Error => err
293+ case err . status_code . to_i
294+ when 403
295+ UI . crash! ( ErrorMessage ::PERMISSION_DENIED_ERROR )
296+ else
297+ UI . crash! ( "#{ ErrorMessage . upload_binary_error ( binary_type ) } (#{ err } , status_code: #{ err . status_code } )" )
298+ end
299+ end
291300
292301 Google ::Apis ::FirebaseappdistributionV1 ::GoogleLongrunningOperation . from_json ( response )
293302 end
0 commit comments