Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Created April 20, 2021 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankitvijay/e0c03d9983e5d30087fa6e9261ec796c to your computer and use it in GitHub Desktop.
Save ankitvijay/e0c03d9983e5d30087fa6e9261ec796c to your computer and use it in GitHub Desktop.
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