Response Body does not show detail stack trace of exception generated

Hi,

I am sending some array of data to service and it is expected to throw SQL exception. In my application I am catching this exception and logging into response body. However, for one particular service, it is not showing any response body. Not sure what mistake I am doing here. Can you pls. suggest areas to look into ?

Request Object-

[Api("CRUD for bulk VirtualServers - VMWares")]
[Route("/VirtualServer_VMWareBulk", "POST", Summary = "Create bulk VMWare virtual servers")]
public class CreateVirtualVmWareBulkRequestDto : List<CreateVirtualVmWareRequestDto>
{

}

public class CreateVirtualVmWareBulkRequestDtoResponse : List<CreateVirtualVMWareDtoResponse>
{

}

Request Dto and Response Dto-

[Api("CRUD for VirtualServer - VMWare")]
//[Route("/VirtualServer/VMWare/", "POST", Summary = "Create a VMWare virtual server")]
[Route("/VirtualServer_VMWare/", "POST", Summary = "Create a VMWare virtual server")]
public class CreateVirtualVmWareRequestDto : IReturn<CreateVirtualVMWareDtoResponse>
{
    public string VM { get; set; }
    public string DNS { get; set; }
    public string Power_State { get; set; }
    public int? CPUs { get; set; }
    public string Memory { get; set; }
    public string NICs { get; set; }
    public int? Disks { get; set; }
    public string Network_1 { get; set; }
    public string Network_2 { get; set; }
    public string Network_3 { get; set; }
    public string Network_4 { get; set; }
    public string Folder { get; set; }
    public string Provisioned_MB { get; set; }
    public string InUseMB { get; set; }
    public string Path { get; set; }
    public string Annotation { get; set; }
    public string DataCenter { get; set; }
    public string Cluster { get; set; }
    public string Host { get; set; }
    public string OS { get; set; }
    public string Meta { get; set; }
    [IgnoreDataMember]
    public bool Bulk { get; set; }
}

public class CreateVirtualVMWareDtoResponse : IHasResponseStatus
{
    public int Id { get; set; }
    public ResponseStatus ResponseStatus { get; set; }
}

Bulk Service Interface-


/// <summary>
    /// Bulk Insert VirtualServer_VMWare
    /// </summary>
    [Authenticate]
    public sealed class VirtualServer_VMWareServiceBulk : Service
    {
        private VirtualServer_VMWareService _service;

        public VirtualServer_VMWareServiceBulk()
        {
            _service = new VirtualServer_VMWareService();
        }

        public CreateVirtualVmWareBulkRequestDtoResponse Post(CreateVirtualVmWareBulkRequestDto request)
        {
            var result = new CreateVirtualVmWareBulkRequestDtoResponse();
            request.ForEach(req => req.Bulk = true);
            result.AddRange(request.Map(x => _service.Post(x)));
            return result;
        }
        public UpdateVirtualVmWareBulkRequestDtoResponse Put(UpdateVirtualVmWareBulkRequestDto requests)
        {
            var results = new UpdateVirtualVmWareBulkRequestDtoResponse();
            requests.ForEach(req => req.Bulk = true);
            results.AddRange(requests.Map(x => _service.Put(x)));
            return results;
        }
        public DeleteVirtualVmWareBulkRequestDtoResponse Delete(DeleteVirtualVmWareBulkRequestDto request)
        {
            var result = new DeleteVirtualVmWareBulkRequestDtoResponse();
            result.AddRange(request.Map(x => _service.Delete(x)));
            return result;
        }
    }

**Single Service Interface**
[Authenticate]
public sealed class VirtualServer_VMWareService : Service
{
    private readonly IVirtualServer_VMWareLogic _logic;

    public VirtualServer_VMWareService()
    {
        _logic = new VirtualServer_VMWareLogic(this.SessionAs<InventoryUserSession>());
    }

    public CreateVirtualVMWareDtoResponse Post(CreateVirtualVmWareRequestDto requestDto)
    {
        var result = new CreateVirtualVMWareDtoResponse();
        var returnValue = _logic.CreateVirtualServer_VMWare(requestDto.ConvertTo<VirtualServer_VMWareBo>());

        result.Id = returnValue;
        result.ResponseStatus = returnValue > 0
            ? new ResponseStatus() { Message = "Device created successfully." }
            : new ResponseStatus() { Message = "Device creation failed.", ErrorCode = "Create failed" };

        return result;
    }

    public UpdateVirtualVMWareDtoResponse Put(UpdateVirtualVmWareRequestDto request)
    {
        var result = new UpdateVirtualVMWareDtoResponse();
        var returnValue = _logic.UpdateVirtualServer_VMWare(request.ConvertTo<VirtualServer_VMWareBo>());

        result.ResponseStatus = returnValue == 1
            ? new ResponseStatus() { Message = "Device updated successfully." }
            : new ResponseStatus() { Message = "Device update failed.", ErrorCode = "Update failed" };
        return result;
    }

    public DeleteVirtualVMWareDtoResponse Delete(DeleteVirtualVmWareRequestDto request)
    {
        var result = new DeleteVirtualVMWareDtoResponse();
        var returnValue = _logic.DeleteVirtualServer_VMWare(request.Id, request.ForceDelete);
        result.ResponseStatus = returnValue == 1
            ? new ResponseStatus() { Message = "Device deleted successfully." }
            : new ResponseStatus() { Message = "Device delete failed.", ErrorCode = "Delete failed" };

        return result;
    }
}

Error Logger Format-
I am logging error by using following method in specific format across all services -

public void ErrorFormat(string format, params object[] args)
{
    var stringBuilder = new StringBuilder();
    stringBuilder.AppendFormat(format, args);
    stringBuilder.Append(Environment.NewLine);
    stringBuilder.Append(Environment.NewLine);
    stringBuilder.AppendFormat(@" ServerName:{0}", Environment.MachineName);
    this.IncomingWebHookUrl.PostJsonToUrl(new { text = stringBuilder.ToString() });
}

However, when similar kind of exception occurs in other service, it shows me proper response body like-

But not for above case-

Your Response DTO needs a ResponseStatus property in order to capture the structured error information which CreateVirtualVmWareBulkRequestDtoResponse doesn’t have, note your DTOs can’t inherit from an IEnumerable<T> and have properties, most serializers only allow arrays or objects separately, not combined so your CreateVirtualVmWareBulkRequestDtoResponse should not inherit from a List<T> it should include the results in the Response DTO along with a ResponseStatus property, e.g:

public class CreateVirtualVmWareBulkRequestDtoResponse 
{
    public List<CreateVirtualVMWareDtoResponse> Results { get; set; }
    public ResponseStatus ResponseStatus { get; set; }
}

Thanks,
however I would like to bring into notice that, another service, which has same structure shows proper response body (as shown in screen shot). Don’t know what is the issue with service.

Response DTOs should not inherit from an IEnumarable, so you should change it. If it returns an Error Response DTO but doesn’t have a ResponseStatus then the Response DTO isn’t following the Response DTO Convention, i.e. if you use a {RequestDto}Response suffix that Response DTO will be returned and if it doesn’t have a ResponseStatus property it will not have any error information.

And this is my wrapper for bulk response -
public class CreateVirtualVmWareBulkRequestDtoResponse : List of CreateVirtualVMWareDtoResponse
{
}