Class BadRequestException
- Namespace
- Cuemon.AspNetCore.Http
- Assembly
- Cuemon.AspNetCore.dll
The exception that is thrown when the server could not understand the request due to invalid syntax.
public class BadRequestException : HttpStatusCodeException, ISerializable
- Inheritance
-
BadRequestException
- Implements
- Inherited Members
Examples
The following example demonstrates how to use BadRequestException for model validation errors in an API controller.
using System;
namespace Cuemon.AspNetCore.Http;
public static class BadRequestExceptionExample
{
public static void Demonstrate()
{
var missingFields = new[] { "email", "displayName" };
var exception = new BadRequestException(
$"The JSON payload is missing required fields: {string.Join(", ", missingFields)}.",
new FormatException("Unexpected end of JSON input."));
Console.WriteLine(exception.StatusCode);
Console.WriteLine(exception.Message);
Console.WriteLine(exception.InnerException?.Message);
}
}
Constructors
BadRequestException()
Initializes a new instance of the BadRequestException class.
public BadRequestException()
BadRequestException(Exception)
Initializes a new instance of the BadRequestException class.
public BadRequestException(Exception innerException)
Parameters
innerExceptionExceptionThe exception that is the cause of the current exception.
BadRequestException(string, Exception)
Initializes a new instance of the BadRequestException class.
public BadRequestException(string message, Exception innerException = null)
Parameters
messagestringThe message that describes the HTTP status code.
innerExceptionExceptionThe exception that is the cause of the current exception.