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 exception = new BadRequestException(
"The JSON payload is missing the required 'email' field.",
new FormatException("Unexpected end of JSON input."));
Console.WriteLine(exception.StatusCode);
Console.WriteLine(exception.InnerException?.GetType().Name);
}
}
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.