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): Unhandled exceptions fix #592

Merged
merged 4 commits into from
Sep 28, 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 @@ -109,6 +109,10 @@ public async Task<ActionResult<ApiResourceAllocationRequest>> CreateProjectAlloc

return Created($"/projects/{projectIdentifier}/requests/{newRequest!.RequestId}", new ApiResourceAllocationRequest(newRequest));
}
catch (InvalidOperationException iv)
{
return ApiErrors.InvalidOperation(iv);
}
catch (ValidationException ex)
{
return ApiErrors.InvalidOperation(ex);
Expand Down Expand Up @@ -193,6 +197,10 @@ public async Task<ActionResult<ApiResourceAllocationRequest>> CreateProjectAlloc
// Using the requests for position endpoint as created ref.. This is not completely accurate as it could return more than those created. Best option though.
return Created($"/projects/{projectIdentifier}/positions/{request.OrgPositionId}/requests", requests.Select(x => new ApiResourceAllocationRequest(x)).ToList());
}
catch (InvalidOperationException iv)
{
return ApiErrors.InvalidOperation(iv);
}
catch (ValidationException ex)
{
return ApiErrors.InvalidOperation(ex);
Expand Down Expand Up @@ -287,6 +295,10 @@ public async Task<ActionResult<ApiResourceAllocationRequest>> CreateResourceOwne

return Created($"/departments/{departmentPath}/resources/requests/{newRequest!.RequestId}", new ApiResourceAllocationRequest(newRequest));
}
catch (InvalidOperationException iv)
{
return ApiErrors.InvalidOperation(iv);
}
catch (ValidationException ex)
{
return ApiErrors.InvalidOperation(ex);
Expand Down Expand Up @@ -363,6 +375,10 @@ public async Task<ActionResult<ApiResourceAllocationRequest>> PatchInternalReque

return new ApiResourceAllocationRequest(updatedRequest!);
}
catch (InvalidOperationException iv)
{
return ApiErrors.InvalidOperation(iv);
}
catch (ValidationException ve)
{
return ApiErrors.InvalidOperation(ve);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ public class UtilitiesController : ResourceControllerBase
private readonly IFusionTokenProvider tokenProvider;
private readonly IOptions<FusionIntegrationOptions> fusionOptions;

public UtilitiesController(IHttpClientFactory httpClientFactory, IFusionTokenProvider tokenProvider, IOptions<FusionIntegrationOptions> fusionOptions)
public UtilitiesController(IHttpClientFactory httpClientFactory, IFusionTokenProvider tokenProvider,
IOptions<FusionIntegrationOptions> fusionOptions)
{
this.httpClientFactory = httpClientFactory;
this.tokenProvider = tokenProvider;
this.fusionOptions = fusionOptions;
}

[HttpPost("/utilities/parse-spreadsheet")]
public async Task<ActionResult<ExcelConversion>> ValidateContractorImportSpreadsheet([FromForm] ConvertSpreadsheetRequest request)
public async Task<ActionResult<ExcelConversion>> ValidateContractorImportSpreadsheet(
[FromForm] ConvertSpreadsheetRequest request)
{
if (request == null)
return FusionApiError.InvalidOperation("MissingBody", "Could not locate any body payload");
Expand All @@ -57,14 +59,16 @@ public async Task<ActionResult<ExcelConversion>> ValidateContractorImportSpreads
if (response.IsSuccessStatusCode)
return JsonConvert.DeserializeObject<ExcelConversion>(content)!;

throw new InvalidOperationException($"Parser function returned non-successfull response ({response.StatusCode}).");
throw new InvalidOperationException(
$"Parser function returned non-successfull response ({response.StatusCode}).");
}

[HttpGet("/utilities/templates/import-personnel")]
public async Task<FileResult> DownloadImportPersonnelTemplate()
{
const string fileName = "fusion personnel import.xlsx";
using var templateFile = Assembly.GetExecutingAssembly().GetManifestResourceStream("Fusion.Resources.Api.Data.personnel-import-template.xlsx");
using var templateFile = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("Fusion.Resources.Api.Data.personnel-import-template.xlsx");
using var memoryStream = new MemoryStream();

if (templateFile == null)
Expand Down Expand Up @@ -117,6 +121,7 @@ public class ExcelHeader
/// </summary>
public int ColIndex { get; set; }
}

public class ExcelDataRow
{
/// <summary>
Expand Down Expand Up @@ -146,10 +151,14 @@ public class ExcelParserMessage
/// </summary>
public string Cell { get; set; } = null!;

public enum ExcelParserMessageLevel { Information, Warning, Error }

public enum ExcelParserMessageLevel
{
Information,
Warning,
Error
}
}

#endregion
}
}
}
Loading