Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[action][appetize] Raise error when the API returns an unsuccessful response #21816

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions fastlane/lib/fastlane/actions/appetize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def self.run(options)

response = http.request(req)

unless response.code.to_i.between?(200, 299)
UI.user_error!("Error uploading to Appetize.io: received HTTP #{response.code} with body #{response.body}")
end

parse_response(response) # this will raise an exception if something goes wrong

UI.message("App URL: #{Actions.lane_context[SharedValues::APPETIZE_APP_URL]}")
Expand Down
14 changes: 14 additions & 0 deletions fastlane/spec/actions_specs/appetize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
allow(request).to receive(:body=).with(kind_of(String)).and_return(response)

allow(response).to receive(:body).and_return(response_string)
allow(response).to receive(:code).and_return('200')
end

describe "Appetize Integration" do
Expand Down Expand Up @@ -72,6 +73,19 @@
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::APPETIZE_API_HOST]).to eql('api.appetize.io')
end

it "raises an error when the API returns an unsuccessful status code" do
allow(response).to receive(:code).and_return('401')
allow(response).to receive(:body).and_return('{"message": "Invalid Key"}')
expect do
Fastlane::FastFile.new.parse("lane :test do
appetize({
api_token: '#{api_token}',
url: '#{url}'
})
end").runner.execute(:test)
end.to raise_error(FastlaneCore::Interface::FastlaneError, /Error uploading to Appetize.io: received HTTP 401 with body {"message": "Invalid Key"}/)
end

it "works with custom API host" do
expect do
Fastlane::FastFile.new.parse("lane :test do
Expand Down