Skip to content

Commit

Permalink
Tying/not typing in backshlash shouldn't break api. Exceptions can be…
Browse files Browse the repository at this point in the history
… thrown by different part of JenkinsApi than expected.
  • Loading branch information
dominikgolda committed Apr 16, 2019
1 parent 4947036 commit 18cbe5c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/Soloplan.WhatsON.Jenkins/JenkinsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task<JenkinsJob> GetJenkinsJob(JenkinsProject subject, Cancellation
var port = subject.GetPort();
var projectName = subject.GetProject();

var jobRequest = $"{address}:{port}/job/{projectName}/api/json?tree={JenkinsJob.RequestProperties}";
var jobRequest = $"{address.Trim('/')}:{port}/job/{projectName.Trim('/')}/api/json?tree={JenkinsJob.RequestProperties}";
return await GetJenkinsModel<JenkinsJob>(subject, jobRequest, token);
}

Expand All @@ -28,17 +28,18 @@ public async Task<JenkinsBuild> GetJenkinsBuild(JenkinsProject subject, int buil
var port = subject.GetPort();
var projectName = subject.GetProject();

var buildRequest = $"{address}:{port}/job/{projectName}/{buildNumber}/api/json?tree={JenkinsBuild.RequestProperties}";
var buildRequest = $"{address.Trim('/')}:{port}/job/{projectName.Trim('/')}/{buildNumber}/api/json?tree={JenkinsBuild.RequestProperties}";
return await GetJenkinsModel<JenkinsBuild>(subject, buildRequest, token);
}

private static async Task<TModel> GetJenkinsModel<TModel>(JenkinsProject subject, string requestUrl, CancellationToken token)
where TModel : class
{
var request = WebRequest.Create(requestUrl);
using (token.Register(() => request.Abort(), false))
using (var response = await request.GetResponseAsync())
try
{
try
using (token.Register(() => request.Abort(), false))
using (var response = await request.GetResponseAsync())
{
// Get the stream containing content returned by the server
// Open the stream using a StreamReader for easy access
Expand All @@ -49,15 +50,15 @@ private static async Task<TModel> GetJenkinsModel<TModel>(JenkinsProject subject
return JsonConvert.DeserializeObject<TModel>(responseFromServer);
}
}
catch (WebException ex)
}
catch (WebException ex)
{
if (token.IsCancellationRequested)
{
if (token.IsCancellationRequested)
{
throw new OperationCanceledException(ex.Message, ex, token);
}

throw;
throw new OperationCanceledException(ex.Message, ex, token);
}

throw;
}
}
}
Expand Down

0 comments on commit 18cbe5c

Please sign in to comment.