Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Consistent Error Logging - Exception for different Error Status codes
using System;
using System.Runtime.Serialization;
[Serializable]
// Used for HttpStatusCode 404 (NotFound)
public class ResourceNotFoundException : Exception
{
public ResourceNotFoundException(string message) : base(message)
{
}
public ResourceNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
protected ResourceNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
using System;
using System.Runtime.Serialization;
[Serializable]
// Used for HttpStatusCode 400 (BadRequest) or 422 (UnprocessableEntity)
public class DomainException : Exception
{
public DomainException(string message) : base(message)
{
}
public DomainException(string message, Exception innerException) : base(message, innerException)
{
}
protected DomainException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
using System;
using System.Runtime.Serialization;
[Serializable]
// Used for HttpStatusCode 403 (Forbidden)
public class UnauthorizedException : Exception
{
public UnauthorizedException(string message) : base(message)
{
}
public UnauthorizedException(string message, Exception innerException) : base(message, innerException)
{
}
protected UnauthorizedException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment