Skip to content

Commit

Permalink
Merge pull request #292 from ifad/chore/no-raise-rescue
Browse files Browse the repository at this point in the history
Use respond instead of raise and rescue
  • Loading branch information
tagliala authored Sep 16, 2024
2 parents 6e5cbc3 + 8f832a1 commit 797db53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class App < Sinatra::Base
elsif params[:url]
Net::HTTP.get URI(params[:url])
else
raise Error.new 400, "Please specify either 'file' or 'url' POST variable"
return respond 400, "Please specify either 'file' or 'url' POST variable"
end
path = LegacyConverter.new.convert_file params[:action], body, params[:language]
converted_url = @legacy_url_base + path
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def show_backtrace(response)
expect(last_response.status).to eq 400
body = JSON.parse(last_response.body)
expect(body).to be_a Hash
expect(body['description'].to_s).to eq "missing file parameter"
expect(body['description']).to eq "missing file parameter"
end
end

Expand All @@ -275,7 +275,7 @@ def show_backtrace(response)
expect(last_response.status).to eq 400
body = JSON.parse(last_response.body)
expect(body).to be_a Hash
expect(body['description'].to_s).to eq "invalid file parameter"
expect(body['description']).to eq "invalid file parameter"
end
end

Expand Down Expand Up @@ -324,7 +324,7 @@ def show_backtrace(response)
expect(last_response.content_type).to eq 'application/json'
body = JSON.parse(last_response.body)
expect(body).to be_a Hash
expect(body['converted'].to_s).not_to eq ''
expect(body['converted']).not_to eq ''
end

it 'converts and saves URL' do
Expand All @@ -341,7 +341,7 @@ def show_backtrace(response)
expect(last_response.content_type).to eq 'application/json'
body = JSON.parse(last_response.body)
expect(body).to be_a Hash
expect(body['converted'].to_s).not_to eq ''
expect(body['converted']).not_to eq ''
end

it 'returns correct JSON structure on fail' do
Expand All @@ -367,7 +367,7 @@ def show_backtrace(response)
expect(last_response.content_type).to eq 'application/json'
body = JSON.parse(last_response.body)
expect(body).to be_a Hash
expect(body['error']).to eq "Please specify either 'file' or 'url' POST variable"
expect(body['description']).to eq "Please specify either 'file' or 'url' POST variable"
end
end
end
Expand All @@ -387,7 +387,7 @@ def show_backtrace(response)
expect(last_response.content_type).to eq 'application/json'
body = JSON.parse(last_response.body)
expect(body).to be_a Hash
expect(body['error'].to_s).not_to eq ''
expect(body['error']).to eq 'File does not exists'
end
end
end

0 comments on commit 797db53

Please sign in to comment.