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

(fix)Api: Added exception handling for provisioning requests #604

Merged
merged 3 commits into from
Nov 16, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using static Fusion.Resources.Logic.Commands.ResourceAllocationRequest;

namespace Fusion.Resources.Api.Controllers
{
Expand Down Expand Up @@ -936,6 +937,10 @@ await DispatchCommandAsync(new Logic.Commands.ResourceAllocationRequest.Provisio
{
return ApiErrors.InvalidOperation(ex);
}
catch (ProvisioningError proEx)
{
return ApiErrors.InvalidOperation(proEx);
}
}

[HttpPost("/projects/{projectIdentifier}/requests/{requestId}/approve")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,28 @@ private async Task AllocateRequestInstanceAsync(DbResourceAllocationRequest dbRe
if (!string.IsNullOrEmpty(dbRequest.ProposedChanges))
proposedChanges = JObject.Parse(dbRequest.ProposedChanges);

if (dbRequest.ProposedPerson.AzureUniqueId != null)
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.AssignedPerson, new ApiPersonV2() { AzureUniqueId = dbRequest.ProposedPerson.AzureUniqueId });
try
{
if (dbRequest.ProposedPerson.AzureUniqueId != null)
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.AssignedPerson, new ApiPersonV2() { AzureUniqueId = dbRequest.ProposedPerson.AzureUniqueId });


if (proposedChanges.TryGetValue("workload", StringComparison.InvariantCultureIgnoreCase, out var workload))
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.Workload!, workload);
if (proposedChanges.TryGetValue("workload", StringComparison.InvariantCultureIgnoreCase, out var workload))
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.Workload!, workload);

if (proposedChanges.TryGetValue("appliesFrom", StringComparison.InvariantCultureIgnoreCase, out var appliesFrom))
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.AppliesFrom, appliesFrom);
if (proposedChanges.TryGetValue("appliesFrom", StringComparison.InvariantCultureIgnoreCase, out var appliesFrom))
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.AppliesFrom, appliesFrom);

if (proposedChanges.TryGetValue("appliesTo", StringComparison.InvariantCultureIgnoreCase, out var appliesTo))
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.AppliesTo, appliesTo);
if (proposedChanges.TryGetValue("appliesTo", StringComparison.InvariantCultureIgnoreCase, out var appliesTo))
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.AppliesTo, appliesTo);

if (proposedChanges.TryGetValue("location", StringComparison.InvariantCultureIgnoreCase, out var location))
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.Location, location.ToObject<ApiPositionLocationV2>()!);
if (proposedChanges.TryGetValue("location", StringComparison.InvariantCultureIgnoreCase, out var location))
instancePatchRequest.SetPropertyValue<ApiPositionInstanceV2>(i => i.Location, location.ToObject<ApiPositionLocationV2>()!);
}
catch (Exception ex)
{
throw new ProvisioningError("Invalid data from request", ex);
}

var url = $"/projects/{dbRequest.Project.OrgProjectId}/drafts/{draft.Id}/positions/{dbRequest.OrgPositionId}/instances/{dbRequest.OrgPositionInstance.Id}?api-version=2.0";
var updateResp = await client.PatchAsync<ApiPositionInstanceV2>(url, instancePatchRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,15 @@ private async Task ExecuteProvisioningAsync(DbResourceAllocationRequest dbReques
dbRequest.ProvisioningStatus.ErrorMessage = $"Received error from Org service when trying to update the position: '{apiError.Error?.Message}'";
dbRequest.ProvisioningStatus.ErrorPayload = apiError.ResponseText;
dbRequest.ProvisioningStatus.State = DbResourceAllocationRequest.DbProvisionState.Error;

throw new ProvisioningError($"Error communicating with org chart: {apiError.Message}", apiError);
}
catch (ProvisioningError ex)
{
dbRequest.ProvisioningStatus.ErrorMessage = $"Error when trying to update the position: '{ex?.Message}'";
dbRequest.ProvisioningStatus.ErrorPayload = ex.InnerException.ToString();
dbRequest.ProvisioningStatus.State = DbResourceAllocationRequest.DbProvisionState.Error;
throw new ProvisioningError($" {ex.Message}", ex);
}
}


Expand Down
Loading