Exception type name stamped into ResponseStatus.Message

I’ve been battling with this for a while, so apologies if its user error but I cannot find the issue.

I’m developing a server rendered blazor web app and am making a JsonApiClient request to a service whose response is marked with IHasErrorStatus and has a ResponseStatus, but the responsestatus is populated with the Exception type name, rather than the exception’s message. What could I be doing wrong?

public class PatchTableMappingResponse : IHasErrorStatus
{
    public int TargetTableId { get; set; }
    public string TargetTable { get; set; } = null!;
    public bool Ignore { get; set; }
    public bool AutoResolve { get; set; }
    public bool Extend { get; set; }
    
    public ResponseStatus? Error { get; }
}
public async Task<PatchTableMappingResponse> PatchAsync(PatchTableMapping request)
{
    CheckDataSyncIsPaused();
    
    var existingTableMapping = Db.Single<dsMapping.TargetTable>(tt => tt.TargetTableId == request.TargetTableId);

    if (existingTableMapping == null)
    {
        throw new NotFoundException("Table mapping not found.");
    }
    
    if (PatchTableMappingValues(existingTableMapping, request))
    {
        try
        {
            await Db.SaveAsync(existingTableMapping);
        }
        catch (SqlException ex) when (
            ex.Number == 2601 || //Cannot insert duplicate key row in object '<Object Name>' with unique index '<Index Name>'.
            ex.Number == 2627) // Violation of PRIMARY KEY constraint '%.*ls'. Cannot insert duplicate key in object '%.*ls'.
        {
            throw new NameNotUniqueException("Target table name must be unique.");
        }
    }

    return new PatchTableMappingResponse
    {
        TargetTableId = existingTableMapping.TargetTableId,
        TargetTable = existingTableMapping.TargetTableName ?? string.Empty,
        Ignore = !existingTableMapping.ShouldProcess,
        AutoResolve = existingTableMapping.ShouldAutoResolve,
        Extend = existingTableMapping.ShouldExtend
    };
}

Response DTOs captures errors in their ResponseStatus property, so if you want to implement an interface it should be implementing IHasResponseStatus instead.

1 Like

Originally, the response dto didn’t have an interface and the response status was defined as

public ResponseStatus ResponseStatus { get; set; }

That exhibited the same behaviour, but now that I’ve tried what you suggested - its worked. Was pulling my hair out - thanks