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:
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user