Skip to content

Commit b9666fc

Browse files
committed
Static function is created that returns the profile to load.
1 parent a088871 commit b9666fc

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/MakingSense.AspNetCore.HypermediaApi/ExceptionHandling/ApiErrorHandlerMiddleware.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,11 @@ private static void WriteResponseHeaders(Problem problem, HttpRequest request, H
165165

166166
response.OnStarting((o) =>
167167
{
168-
if (acceptsProblemType)
169-
response.ContentType = PROBLEM_MEDIATYPE;
170-
else
171-
AddQuotedProfileToContentType(response, keepUnquoted);
168+
response.ContentType = acceptsProblemType ? PROBLEM_MEDIATYPE
169+
: response.ContentType + CreateProfileContentType(keepUnquoted);
172170
return Task.FromResult(0);
173171
}, null);
174172

175-
176173
foreach (var pair in problem.GetCustomHeaders())
177174
{
178175
response.Headers[pair.Key] = pair.Value;
@@ -182,11 +179,11 @@ private static void WriteResponseHeaders(Problem problem, HttpRequest request, H
182179
response.StatusCode = problem.status;
183180
}
184181

185-
private static void AddQuotedProfileToContentType(HttpResponse response, bool keepUnquoted = false)
182+
private static String CreateProfileContentType(bool keepUnquoted = false)
186183
{
187-
var profile = keepUnquoted ? SchemaAttribute.Path
188-
: $"\"{SchemaAttribute.Path?.Replace("\"", "\\\"")}";
189-
response.ContentType += $"; profile={profile}problem.json\"";
184+
var profile = keepUnquoted ? SchemaAttribute.Path + "problem.json"
185+
: $"\"{SchemaAttribute.Path?.Replace("\"", "\\\"")}" + "problem.json\"";
186+
return $"; profile={profile}";
190187
}
191188
}
192189
}

0 commit comments

Comments
 (0)