Table of Contents

BadRequestException Class

Definition

Namespace
Cuemon.AspNetCore.Http
Assemblies
Cuemon.AspNetCore.dll
Source
src/Cuemon.AspNetCore/Http/BadRequestException.cs

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.

// Program.cs
using System;
using Cuemon.AspNetCore.Http;

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

Name Description
BadRequestException()

Initializes a new instance of the BadRequestException class.

BadRequestException(Exception)

Initializes a new instance of the BadRequestException class.

BadRequestException(string, Exception)

Initializes a new instance of the BadRequestException class.

See Also