Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

9 Comments

  1. Should I return BadRequest in Controller or throw an exception that will be handled in the middleware?

  2. Hi, Mukesh!
    Did I understand correctly that if we call an exception «throw new SomeException(“An error occurred…”);» it will fall on the current line and after we will see information about it in middleware? I just thought that if there is an error, we will not see an exception on the line where it occurred

  3. Very helpful, thank you! 😀

    I ended up using the extension method `response.WriteAsJsonAsync(responseModel)` instead of the below:
    “`
    var result = JsonSerializer.Serialize(responseModel);
    await response.WriteAsync(result);
    “`