Skip to content

Commit

Permalink
Implementing 404 error when repo is not found (#11449)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamThorenfeldt authored and nkylstad committed Nov 1, 2023
1 parent de75623 commit 05a2ab8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/src/Designer/Filters/Git/GitErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public class GitErrorCodes
{
public const string NonFastForwardError = "GT_01";
public const string RepositoryNotFound = "GT_02";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 05a2ab8

Please sign in to comment.