异常信息 API 接口

 

public class ApiException : Exception
{
    public int ErrorCode { get; }
    public string ErrorMessage { get; }

    public ApiException(int errorCode, string errorMessage)
    {
        ErrorCode = errorCode;
        ErrorMessage = errorMessage;
    }
}

// 派生自 ApiException 的具体异常类
public class InvalidRequestException : ApiException
{
    public InvalidRequestException() : base(1001, "Invalid request")
    {
    }
}

public class ForbiddenException : ApiException
{
    public ForbiddenException() : base(2001, "Forbidden")
    {
    }
}

public class NotFoundException : ApiException
{
    public NotFoundException(string resource) : base(3001, $"{resource} not found")
    {
    }
}

public class InternalServerErrorException : ApiException
{
    public InternalServerErrorException() : base(4001, "Internal server error")
    {
    }
}

 

posted @ 2023-12-07 15:00  ProZkb  阅读(8)  评论(0编辑  收藏  举报