Skip to content

Commit

Permalink
Handle 405 errors (#3777)
Browse files Browse the repository at this point in the history
* Handle 405 error

* Updated the diagnosticInfo

* Added unit test

* Updated tests
  • Loading branch information
apurvabhaleMS authored Mar 29, 2024
1 parent 64d456b commit ae6128c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Microsoft.Health.Fhir.Api/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Microsoft.Health.Fhir.Api/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@
<value>The requested "{0}" operation is not supported.</value>
<comment>{0} is the operation name</comment>
</data>
<data name="OperationNotSupported" xml:space="preserve">
<value>The requested operation is not supported.</value>
</data>
<data name="PageTitle" xml:space="preserve">
<value>FHIR Server</value>
<comment>{NumberedPlaceHolder="FHIR"}</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public IActionResult CustomError(int? statusCode = null)
returnCode = HttpStatusCode.NotFound;
diagnosticInfo = Resources.NotFoundException;
break;
case (int)HttpStatusCode.MethodNotAllowed:
issueType = OperationOutcome.IssueType.NotSupported;
returnCode = HttpStatusCode.MethodNotAllowed;
diagnosticInfo = Resources.OperationNotSupported;
break;
default:
issueType = OperationOutcome.IssueType.Exception;
returnCode = HttpStatusCode.InternalServerError;
Expand Down
13 changes: 13 additions & 0 deletions test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.Net;
using System.Net.Http;
using Hl7.Fhir.Model;
using Hl7.Fhir.Validation;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -102,6 +103,18 @@ public async Task GivenAnUnknownRoute_WhenPostingToHttp_TheServerShouldReturnAnO
DotNetAttributeValidation.Validate(operationOutcome, true);
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenANotAllowedMethod_WhenRequestIsSent_TheServerShouldReturnMethodNotSupported()
{
using var requestMessage = new HttpRequestMessage();
string uriString = _client.HttpClient.BaseAddress + "admin.html";
requestMessage.RequestUri = new Uri(uriString);
requestMessage.Method = HttpMethod.Head;
HttpResponseMessage response = await _client.HttpClient.SendAsync(requestMessage);
Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
}

public class StartupWithThrowingMiddleware : StartupBaseForCustomProviders
{
public StartupWithThrowingMiddleware(IConfiguration configuration)
Expand Down

0 comments on commit ae6128c

Please sign in to comment.