Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Implement global exception handling using middleware to catch unhandled exceptions. Return consistent and meaningful error responses. Log errors for debugging and monitoring. Example in ASP.NET Core: pp.UseExceptionHandl…
Answer: PIs? Return a structured JSON response with: status → HTTP status code error → Short message details → Optional for debugging Example: { "status": 400, "error": "Bad Request", "details": "Email is required" } Wha…
404 Not Found indicates the requested resource does not exist. Use it when a client requests an invalid ID or non-existent resource. Helps clients gracefully handle missing data. Example in ASP.NET Core: var user = dbCon…
Use model validation with data annotations. Return 400 Bad Request with a list of validation errors. Example: public class UserModel { [Required(ErrorMessage = "Email is required")] [EmailAddress(ErrorMessage = "Invalid…
PI? Structured logging with libraries like Serilog, NLog, or built-in ILogger. Log requests and responses, including headers and payloads (avoid sensitive info). Use correlation IDs to trace requests across services. Cen…
ASP.NET Web API ASP.NET Core Web API Tutorial · REST API
exceptions.
Example in ASP.NET Core:
pp.UseExceptionHandler(appError =>
{
ppError.Run(async context =>
{
context.Response.StatusCode = 500; // Internal Server Error
context.Response.ContentType = "application/json";
var contextFeature =
context.Features.Get<IExceptionHandlerFeature>();
if(contextFeature != null)
{
// Log exception (use ILogger)
wait context.Response.WriteAsync(new
{
StatusCode = context.Response.StatusCode,
Message = "Internal Server Error.",
Detail = contextFeature.Error.Message
}.ToString());
}
});
});
ASP.NET Web API ASP.NET Core Web API Tutorial · REST API
Answer: PIs? Return a structured JSON response with: status → HTTP status code error → Short message details → Optional for debugging Example: { "status": 400, "error": "Bad Request", "details": "Email is required" }
In a production ASP.NET Web API application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
ASP.NET Web API ASP.NET Core Web API Tutorial · REST API
Example in ASP.NET Core:
var user = dbContext.Users.Find(id);
if (user == null)
{
return NotFound(new { status = 404, error = "User not found" });
}ASP.NET Web API ASP.NET Core Web API Tutorial · REST API
Example:
public class UserModel
{
[Required(ErrorMessage = "Email is required")]
[EmailAddress(ErrorMessage = "Invalid email format")]
public string Email { get; set; }
[Required]
[MinLength(6, ErrorMessage = "Password must be at least 6
characters")]
public string Password { get; set; }
}
// Controller action
[HttpPost("register")]
public IActionResult Register([FromBody] UserModel model)
{
if (!ModelState.IsValid)
{
var errors = ModelState.Values.SelectMany(v =>
v.Errors).Select(e => e.ErrorMessage);
return BadRequest(new { status = 400, error = "Validation
Failed", details = errors });
}
return Ok("User registered successfully");
}ASP.NET Web API ASP.NET Core Web API Tutorial · REST API
PI?
Example using ILogger in ASP.NET Core:
private readonly ILogger<MyController> _logger;
public MyController(ILogger<MyController> logger)
{
_logger = logger;
}
[HttpGet("{id}")]
public IActionResult GetUser(int id)
{
_logger.LogInformation("Fetching user with id {UserId}", id);
try
{
var user = dbContext.Users.Find(id);
if (user == null)
{
_logger.LogWarning("User with id {UserId} not found",
id);
return NotFound();
}
return Ok(user);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error fetching user with id {UserId}",
id);
return StatusCode(500, "Internal Server Error");
}
}
This covers all core aspects of error handling and debugging for REST APIs.