support better errorhandling for codeharbor

This commit is contained in:
Karol
2019-10-25 16:25:57 +02:00
parent c0a0b44c4d
commit 3912caab1c
6 changed files with 63 additions and 38 deletions

View File

@ -10,11 +10,7 @@ module ExerciseService
def execute
body = @zip.string
begin
conn = Faraday.new(url: @codeharbor_link.push_url) do |faraday|
faraday.adapter Faraday.default_adapter
end
response = conn.post do |request|
response = connection.post do |request|
request.headers['Content-Type'] = 'application/zip'
request.headers['Content-Length'] = body.length.to_s
request.headers['Authorization'] = 'Bearer ' + @codeharbor_link.api_key
@ -26,5 +22,13 @@ module ExerciseService
return e.message
end
end
private
def connection
Faraday.new(url: @codeharbor_link.push_url) do |faraday|
faraday.adapter Faraday.default_adapter
end
end
end
end