Return 404 for null body/header in result controllers

Previously, OutResController and ResultViewController returned HTTP 200 OK with an empty object when the response body or header was null. Now, they return HTTP 404 Not Found in these cases, providing more accurate HTTP status codes for missing resources. Non-null bodies or headers continue to return HTTP 200 OK with the deserialized content.
This commit is contained in:
2025-12-17 09:31:58 +01:00
parent 39fcee2b50
commit a92d57d9cf
2 changed files with 4 additions and 4 deletions

View File

@@ -52,8 +52,8 @@ public class OutResController(IMediator mediator, IConfiguration config) : Contr
return resultType switch
{
ResultType.Body => res.Body is null ? Ok(new object { }) : Ok(res.Body.JsonToDynamic()),
ResultType.Header => res.Header is null ? Ok(new object { }) : Ok(res.Header.JsonToDynamic()),
ResultType.Body => res.Body is null ? NotFound() : Ok(res.Body.JsonToDynamic()),
ResultType.Header => res.Header is null ? NotFound() : Ok(res.Header.JsonToDynamic()),
_ => Ok(res),
};
}

View File

@@ -32,8 +32,8 @@ public class ResultViewController(IMediator mediator, IConfiguration config) : C
return resultType switch
{
ResultType.Body => res.Body is null ? Ok(new object { }) : Ok(res.Body.JsonToDynamic()),
ResultType.Header => res.Header is null ? Ok(new object { }) : Ok(res.Header.JsonToDynamic()),
ResultType.Body => res.Body is null ? NotFound() : Ok(res.Body.JsonToDynamic()),
ResultType.Header => res.Header is null ? NotFound() : Ok(res.Header.JsonToDynamic()),
_ => Ok(res),
};
}