Table of Contents

PreconditionFailedException Class

Definition

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

The exception that is thrown when the client has indicated preconditions in its headers which the server does not meet.

public class PreconditionFailedException : HttpStatusCodeException, ISerializable
Inheritance
PreconditionFailedException
Implements
Inherited Members

Examples

The following example demonstrates how to use PreconditionFailedException when a conditional request header check fails.

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

const string currentEtag = "\"v2\"";
const string suppliedEtag = "\"v1\"";
if (!string.Equals(suppliedEtag, currentEtag, StringComparison.Ordinal))
{
    var exception = new PreconditionFailedException(
        $"The supplied If-Match value {suppliedEtag} does not match the current ETag {currentEtag}.",
        new InvalidOperationException("The resource changed after the client read it."));

    Console.WriteLine(exception.StatusCode);
    Console.WriteLine(exception.Message);
    Console.WriteLine(exception.InnerException?.Message);
}

Constructors

Name Description
PreconditionFailedException()

Initializes a new instance of the PreconditionFailedException class.

PreconditionFailedException(Exception)

Initializes a new instance of the PreconditionFailedException class.

PreconditionFailedException(string, Exception)

Initializes a new instance of the PreconditionFailedException class.

See Also