Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 43c546f

Browse files
there is zero benefit to using a different content type for errors
1 parent c1d3e7c commit 43c546f

8 files changed

Lines changed: 18 additions & 30 deletions

File tree

src/SqlStreamStore.HAL.Tests/MiddlewareFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ private MiddlewareFixture(OwinHttpMessageHandler messageHandler)
3636
HttpClient = new HttpClient(_messageHandler)
3737
{
3838
BaseAddress = new UriBuilder().Uri,
39-
DefaultRequestHeaders = { Accept = { new MediaTypeWithQualityHeaderValue("application/hal+json") } }
39+
DefaultRequestHeaders =
40+
{
41+
Accept = { new MediaTypeWithQualityHeaderValue(Constants.Headers.ContentTypes.HalJson) }
42+
}
4043
};
4144
}
4245
public HttpClient HttpClient { get; }

src/SqlStreamStore.HAL.Tests/StreamAppendTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public async Task wrong_expected_version(int[] expectedVersions)
185185
{
186186
response.StatusCode.ShouldBe(HttpStatusCode.Conflict);
187187
response.Content.Headers.ContentType.ShouldBe(new MediaTypeHeaderValue(
188-
Constants.Headers.ContentTypes.ProblemDetails));
188+
Constants.Headers.ContentTypes.HalJson));
189189
}
190190
var page = await _fixture.StreamStore.ReadStreamForwards(StreamId, 0, int.MaxValue);
191191

src/SqlStreamStore.HAL.Tests/StreamDeleteTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async Task wrong_expected_version(int expectedVersion)
5757
{
5858
response.StatusCode.ShouldBe(HttpStatusCode.Conflict);
5959
response.Content.Headers.ContentType.ShouldBe(new MediaTypeHeaderValue(
60-
Constants.Headers.ContentTypes.ProblemDetails));
60+
Constants.Headers.ContentTypes.HalJson));
6161
}
6262

6363
var page = await _fixture.StreamStore.ReadStreamForwards(StreamId, 0, 1);

src/SqlStreamStore.HAL/AppendStreamMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private static MidFunc AppendStream(StreamResource stream) => next => async env
4444
}
4545
catch(WrongExpectedVersionException ex)
4646
{
47-
await context.WriteProblemDetailsResponse(ex);
47+
await context.WriteWrongExpectedVersion(ex);
4848
}
4949
};
5050
}

src/SqlStreamStore.HAL/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public static class Headers
1212

1313
public static class ContentTypes
1414
{
15-
public const string ProblemDetails = "application/problem+json";
1615
public const string Json = "application/json";
16+
public const string HalJson = "application/hal+json";
1717
}
1818
}
1919

src/SqlStreamStore.HAL/DeleteStreamMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private static MidFunc DeleteStream(StreamResource stream) => next => async env
4545
}
4646
catch(WrongExpectedVersionException ex)
4747
{
48-
await context.WriteProblemDetailsResponse(ex);
48+
await context.WriteWrongExpectedVersion(ex);
4949
}
5050
};
5151
}

src/SqlStreamStore.HAL/ExceptionExtensions.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/SqlStreamStore.HAL/OwinContextExtensions.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace SqlStreamStore.HAL
22
{
33
using System.IO;
44
using System.Threading.Tasks;
5+
using Halcyon.HAL;
56
using Microsoft.IO;
67
using Microsoft.Owin;
78
using Newtonsoft.Json;
@@ -15,7 +16,7 @@ private static readonly RecyclableMemoryStreamManager s_StreamManager
1516

1617
public static async Task WriteHalResponse(this IOwinContext context, Response response)
1718
{
18-
context.Response.ContentType = "application/hal+json";
19+
context.Response.ContentType = Constants.Headers.ContentTypes.HalJson;
1920

2021
context.Response.StatusCode = response.StatusCode;
2122

@@ -45,13 +46,13 @@ public static async Task WriteHalResponse(this IOwinContext context, Response re
4546
}
4647
}
4748

48-
public static Task WriteProblemDetailsResponse(this IOwinContext context, WrongExpectedVersionException ex)
49-
{
50-
context.Response.StatusCode = 409;
51-
context.Response.ContentType = Constants.Headers.ContentTypes.ProblemDetails;
52-
53-
return context.Response.WriteAsync(ex.ConvertToProblemDetails(), context.Request.CallCancelled);
54-
}
49+
public static Task WriteWrongExpectedVersion(this IOwinContext context, WrongExpectedVersionException ex)
50+
=> context.WriteHalResponse(new Response(new HALResponse(new
51+
{
52+
type = "WrongExpectedVersion",
53+
title = "Wrong expected version.",
54+
detail = ex.Message
55+
}), 409));
5556

5657
public static bool IsGetOrHead(this IOwinContext context)
5758
=> context.Request.Method == "GET" || context.Request.Method == "HEAD";

0 commit comments

Comments
 (0)