'Unit.Value from MediatR is returning status code 200 instead of 204

consider following code

public async Task<Unit> Handle(UpdateVendorCommand request, CancellationToken cancellationToken)
    {
        var vendor = await _context.Vendor.FindAsync(request.Id);

        if (vendor is null)
            throw new KeyNotFoundException();

        _mapper.Map(request, vendor);
        await _context.SaveChangesAsync();
        return Unit.Value;
    }  

I'm getting status code 200 instead of 204 because I can't return null. How do I return null if my method return type is Task<Unit>? Or is there any alternative beside using Task<Unit>?

My Controller

public class UpdateVendorController : ControllerBase
{
    private readonly IMediator _mediator;

    public UpdateVendorController(IMediator mediator)
    {
        _mediator = mediator;
    }

    [HttpPut]
    [Route("vendor")]
    [SwaggerOperation(Tags = new[] { "Vendor" })]
    public async Task<Unit> UpdateVendor([FromBody] UpdateVendorCommand request)
    {
        return await _mediator.Send(request);
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source