(bugfix): when returning ProblemDetail should be applicaiton/problem+json

This commit is contained in:
Maksym Sadovnychyy 2025-11-03 18:22:02 +01:00
parent f6a7b13326
commit 43abcba816
3 changed files with 12 additions and 12 deletions

View File

@ -8,7 +8,7 @@
<!-- NuGet package metadata -->
<PackageId>MaksIT.Results</PackageId>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
<Authors>Maksym Sadovnychyy</Authors>
<Company>MAKS-IT</Company>
<Product>MaksIT.Results</Product>

View File

@ -1,8 +1,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;
namespace MaksIT.Results.Mvc;
public class ObjectResult(object? value) : IActionResult {
@ -20,7 +18,13 @@ public class ObjectResult(object? value) : IActionResult {
response.StatusCode = StatusCode.Value;
}
response.ContentType = "application/json";
// Set content type based on value type
if (Value is ProblemDetails) {
response.ContentType = "application/problem+json";
}
else {
response.ContentType = "application/json";
}
if (Value is not null) {
await JsonSerializer.SerializeAsync(

View File

@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MaksIT.Results.Mvc;
namespace MaksIT.Results.Mvc;
public class ProblemDetails {
public int? Status { get; set; }
public string? Type { get; set; }
public string? Title { get; set; }
public int? Status { get; set; }
public string? Detail { get; set; }
public string? Instance { get; set; }
public IDictionary<string, object?> Extensions { get; } = new Dictionary<string, object?>();
public IDictionary<string, object?> Extensions { get; set; } = new Dictionary<string, object?>();
}