Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Created April 20, 2021 20:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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