diff --git a/backend/src/Designer/Filters/Git/GitErrorCodes.cs b/backend/src/Designer/Filters/Git/GitErrorCodes.cs index aafa5ee59d8..d3c6393f3ea 100644 --- a/backend/src/Designer/Filters/Git/GitErrorCodes.cs +++ b/backend/src/Designer/Filters/Git/GitErrorCodes.cs @@ -3,5 +3,6 @@ public class GitErrorCodes { public const string NonFastForwardError = "GT_01"; + public const string RepositoryNotFound = "GT_02"; } } diff --git a/backend/src/Designer/Filters/Git/GitExceptionFilterAttribute.cs b/backend/src/Designer/Filters/Git/GitExceptionFilterAttribute.cs index 634fb7eb7f4..1489ee4cfbd 100644 --- a/backend/src/Designer/Filters/Git/GitExceptionFilterAttribute.cs +++ b/backend/src/Designer/Filters/Git/GitExceptionFilterAttribute.cs @@ -25,6 +25,10 @@ public override void OnException(ExceptionContext context) context.Result = new ObjectResult(ProblemDetailsUtils.GenerateProblemDetails(context.Exception, GitErrorCodes.NonFastForwardError, HttpStatusCode.Conflict)) { StatusCode = (int)HttpStatusCode.Conflict }; } + if (context.Exception is LibGit2Sharp.RepositoryNotFoundException) + { + context.Result = new ObjectResult(ProblemDetailsUtils.GenerateProblemDetails(context.Exception, GitErrorCodes.RepositoryNotFound, HttpStatusCode.NotFound)) { StatusCode = (int)HttpStatusCode.NotFound }; + } } } } diff --git a/backend/tests/Designer.Tests/GiteaIntegrationTests/RepositoryControllerGiteaIntegrationTests.cs b/backend/tests/Designer.Tests/GiteaIntegrationTests/RepositoryControllerGiteaIntegrationTests.cs index 49d211ab7c3..b5635df8ca0 100644 --- a/backend/tests/Designer.Tests/GiteaIntegrationTests/RepositoryControllerGiteaIntegrationTests.cs +++ b/backend/tests/Designer.Tests/GiteaIntegrationTests/RepositoryControllerGiteaIntegrationTests.cs @@ -156,6 +156,16 @@ public async Task MetadataAndStatus_ShouldBehaveAsExpected(string org) deserializedRepoStatusModel.RepositoryStatus.Should().Be(RepositoryStatus.Ok); } + [Theory] + [Trait("Category", "GiteaIntegrationTest")] + [InlineData(GiteaConstants.TestOrgUsername)] + public async Task RepoStatus_ShouldReturn404NotFoundWhenInvalidRepo(string org) + { + // Call status endpoint + using HttpResponseMessage statusResponse = await HttpClient.GetAsync($"designer/api/repos/repo/{org}/123/status"); + statusResponse.StatusCode.Should().Be(HttpStatusCode.NotFound); + } + [Theory] [Trait("Category", "GiteaIntegrationTest")] [InlineData(GiteaConstants.TestOrgUsername)]