spaceship/lib/spaceship/connect_api/api_client.rb in fastlane-2.185.1 vs spaceship/lib/spaceship/connect_api/api_client.rb in fastlane-2.186.0

- old
+ new

@@ -205,20 +205,23 @@ return Spaceship::ConnectAPI::Response.new(body: response.body, status: response.status, headers: response.headers, client: self) end # Overridden from Spaceship::Client def handle_error(response) + body = response.body.empty? ? {} : response.body + body = JSON.parse(body) if body.kind_of?(String) + case response.status.to_i when 401 - raise UnauthorizedAccessError, format_errors(response) if response && (response.body || {})['errors'] + raise UnauthorizedAccessError, format_errors(response) when 403 - error = (response.body['errors'] || []).first || {} + error = (body['errors'] || []).first || {} error_code = error['code'] if error_code == "FORBIDDEN.REQUIRED_AGREEMENTS_MISSING_OR_EXPIRED" - raise ProgramLicenseAgreementUpdated, format_errors(response) if response && (response.body || {})['errors'] + raise ProgramLicenseAgreementUpdated, format_errors(response) else - raise AccessForbiddenError, format_errors(response) if response && (response.body || {})['errors'] + raise AccessForbiddenError, format_errors(response) end end end def format_errors(response) @@ -278,19 +281,41 @@ # } # } # ] # } - return response.body['errors'].map do |error| + # Membership expired + # { + # "errors" : [ + # { + # "id" : "UUID", + # "status" : "403", + # "code" : "FORBIDDEN_ERROR", + # "title" : "This request is forbidden for security reasons", + # "detail" : "Team ID: 'ID' is not associated with an active membership. To check your teams membership status, sign in your account on the developer website. https://developer.apple.com/account/" + # } + # ] + # } + + body = response.body.empty? ? {} : response.body + body = JSON.parse(body) if body.kind_of?(String) + + formatted_errors = (body['errors'] || []).map do |error| messages = [[error['title'], error['detail'], error.dig("source", "pointer")].compact.join(" - ")] meta = error["meta"] || {} associated_errors = meta["associatedErrors"] || {} messages + associated_errors.values.flatten.map do |associated_error| [[associated_error["title"], associated_error["detail"]].compact.join(" - ")] end end.flatten.join("\n") + + if formatted_errors.empty? + formatted_errors << "Unknown error" + end + + return formatted_errors end private def local_variable_get(binding, name)