Browse Source

Better status code for exception.

pull/935/head
Sebastian 4 years ago
parent
commit
61800450c8
  1. 30
      backend/src/Squidex.Web/ApiExceptionConverter.cs
  2. 13
      backend/tests/Squidex.Web.Tests/ApiExceptionFilterAttributeTests.cs
  3. 1
      backend/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs

30
backend/src/Squidex.Web/ApiExceptionConverter.cs

@ -20,17 +20,18 @@ namespace Squidex.Web
{ {
private static readonly Dictionary<int, string> Links = new Dictionary<int, string> private static readonly Dictionary<int, string> Links = new Dictionary<int, string>
{ {
[400] = "https://tools.ietf.org/html/rfc7231#section-6.5.1", [400] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.5.1",
[401] = "https://tools.ietf.org/html/rfc7235#section-3.1", [401] = "https://www.rfc-editor.org/rfc/rfc7235#section-3.1",
[403] = "https://tools.ietf.org/html/rfc7231#section-6.5.3", [403] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.5.3",
[404] = "https://tools.ietf.org/html/rfc7231#section-6.5.4", [404] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.5.4",
[406] = "https://tools.ietf.org/html/rfc7231#section-6.5.6", [406] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.5.6",
[409] = "https://tools.ietf.org/html/rfc7231#section-6.5.8", [408] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.5.7",
[410] = "https://tools.ietf.org/html/rfc7231#section-6.5.9", [409] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.5.8",
[412] = "https://tools.ietf.org/html/rfc7231#section-6.5.10", [410] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.5.9",
[415] = "https://tools.ietf.org/html/rfc7231#section-6.5.13", [412] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.5.10",
[422] = "https://tools.ietf.org/html/rfc4918#section-11.2", [415] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.5.13",
[500] = "https://tools.ietf.org/html/rfc7231#section-6.6.1" [422] = "https://www.rfc-editor.org/rfc/rfc4918#section-11.2",
[500] = "https://www.rfc-editor.org/rfc/rfc7231#section-6.6.1"
}; };
public static (ErrorDto Error, Exception? Unhandled) ToErrorDto(int statusCode, HttpContext? httpContext) public static (ErrorDto Error, Exception? Unhandled) ToErrorDto(int statusCode, HttpContext? httpContext)
@ -105,8 +106,11 @@ namespace Squidex.Web
case DomainException ex: case DomainException ex:
return (CreateError(400, ex.Message, ex.ErrorCode), GetInner(exception)); return (CreateError(400, ex.Message, ex.ErrorCode), GetInner(exception));
case SecurityException: case OperationCanceledException:
return (CreateError(403), exception); return (CreateError(408), null);
case SecurityException ex:
return (CreateError(403), ex);
case DecoderFallbackException ex: case DecoderFallbackException ex:
return (CreateError(400, ex.Message), null); return (CreateError(400, ex.Message), null);

13
backend/tests/Squidex.Web.Tests/ApiExceptionFilterAttributeTests.cs

@ -180,6 +180,19 @@ namespace Squidex.Web
.MustNotHaveHappened(); .MustNotHaveHappened();
} }
[Fact]
public void Should_generate_408_for_OperationCanceledException()
{
var context = Error(new OperationCanceledException());
sut.OnException(context);
Validate(408, context.Result, null);
A.CallTo(log)
.MustNotHaveHappened();
}
[Fact] [Fact]
public void Should_generate_403_and_log_for_SecurityException() public void Should_generate_403_and_log_for_SecurityException()
{ {

1
backend/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs

@ -12,6 +12,7 @@ using TestSuite.Model;
namespace TestSuite.ApiTests namespace TestSuite.ApiTests
{ {
[Trait("Category", "NotAutomated")]
public class CDNTests : IClassFixture<ClientCloudFixture> public class CDNTests : IClassFixture<ClientCloudFixture>
{ {
public ClientCloudFixture _ { get; } public ClientCloudFixture _ { get; }

Loading…
Cancel
Save