Skip to content

Commit

Permalink
- Less generic catch.
Browse files Browse the repository at this point in the history
- Reformat foreach and if into where statement.
  • Loading branch information
Konrad-Simso committed Oct 11, 2024
1 parent b24128c commit 6819cfa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion backend/src/Designer/Controllers/OptionsController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;

Check warning on line 1 in backend/src/Designer/Controllers/OptionsController.cs

View workflow job for this annotation

GitHub Actions / Format check

Using directive is unnecessary.
using System.Collections.Generic;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Helpers;
Expand Down Expand Up @@ -149,7 +150,7 @@ public async Task<IActionResult> UploadFile(string org, string repo, [FromForm]
List<Option> newOptionsList = await _optionsService.UploadNewOption(org, repo, developer, fileName, file, cancellationToken);
return Ok(newOptionsList);
}
catch (Exception e)
catch (JsonException e)
{
return BadRequest(e.Message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;

Check warning on line 1 in backend/src/Designer/Services/Implementation/OptionsService.cs

View workflow job for this annotation

GitHub Actions / Format check

Using directive is unnecessary.
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -73,12 +74,10 @@ public async Task<List<Option>> UploadNewOption(string org, string repo, string
List<Option> deserializedOptions = JsonSerializer.Deserialize<List<Option>>(payload.OpenReadStream(),
new JsonSerializerOptions { WriteIndented = true, AllowTrailingCommas = true });

foreach (Option option in deserializedOptions)
IEnumerable<Option> result = deserializedOptions.Where(option => string.IsNullOrEmpty(option.Value) || string.IsNullOrEmpty(option.Label));
if (result.Any())
{
if (string.IsNullOrEmpty(option.Value) || string.IsNullOrEmpty(option.Label))
{
throw new Exception("Uploaded file is missing one of the following attributes for a option: value or label.");
}
throw new JsonException("Uploaded file is missing one of the following attributes for a option: value or label.");
}

var altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, repo, developer);
Expand Down

0 comments on commit 6819cfa

Please sign in to comment.