Skip to content

Commit cee85ea

Browse files
claudiamurialdoclaudiamurialdo
andauthored
Api object: return StatusCode on empty result (#1184)
* The Api object's StatusCode was not being returned when the operation result was empty or null * Unify the logic in GetResponse and EmptyResult to avoid duplication --------- Co-authored-by: claudiamurialdo <c.murialdo@globant.com>
1 parent 7d72a78 commit cee85ea

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRestServices.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,24 +262,28 @@ protected void SetMessages(msglist messages)
262262
AddHeader(WARNING_HEADER, StringUtil.Sanitize(header.ToString(), StringUtil.HttpHeaderWhiteList));
263263
}
264264
}
265-
protected ActionResult GetResponse(object data)
265+
protected ActionResult GetResponse(object data = null)
266266
{
267+
if (_statusCode == HttpStatusCode.NoContent)
268+
return NoContent();
269+
267270
if (_statusCode != HttpStatusCode.OK)
268-
return StatusCode((int)_statusCode, data);
269-
else
270-
return Ok(data);
271+
return data != null ? StatusCode((int)_statusCode, data) : StatusCode((int)_statusCode);
272+
273+
return data != null ? Ok(data) : Ok();
271274
}
272275
protected ActionResult EmptyResult()
273276
{
274-
return Ok();
277+
return GetResponse();
275278
}
279+
276280
protected ActionResult EmptyObjectResult()
277281
{
278-
return Ok(new { });
282+
return GetResponse(new { });
279283
}
280284
protected ActionResult NullResult()
281285
{
282-
return Ok("null");
286+
return GetResponse("null");
283287
}
284288
protected ObjectResult HandleException(Exception ex)
285289
{

0 commit comments

Comments
 (0)