68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Learn.Archives.Core.Common
|
|
{
|
|
/// <summary>
|
|
/// 异常抛出的拓展类
|
|
/// </summary>
|
|
public class Oh
|
|
{
|
|
/// <summary>
|
|
/// 抛出 异常
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="code"></param>
|
|
/// <exception cref="OhException"></exception>
|
|
public static void Error(string message, int code = 500)
|
|
{
|
|
throw new OhException(message, code);
|
|
}
|
|
/// <summary>
|
|
/// 抛出 异常
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="code"></param>
|
|
/// <exception cref="OhException"></exception>
|
|
public static T Error<T>(string message, int code = 500)
|
|
{
|
|
throw new OhException(message, code);
|
|
}
|
|
/// <summary>
|
|
/// 抛出 模型校验异常
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="code"></param>
|
|
/// <exception cref="OhException"></exception>
|
|
public static void ModelError(string message, int code = 400)
|
|
{
|
|
throw new OhException(message, code);
|
|
}
|
|
/// <summary>
|
|
/// 抛出 模型校验异常
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="code"></param>
|
|
/// <exception cref="OhException"></exception>
|
|
public static void ToeknError(string message, int code = 401)
|
|
{
|
|
throw new OhException(message, code);
|
|
}
|
|
}
|
|
public class OhException : Exception
|
|
{
|
|
/// <summary>
|
|
/// 错误码
|
|
/// </summary>
|
|
public virtual int Code { get; }
|
|
public OhException(string message, int code = -1) :base(message)
|
|
{
|
|
Code= code;
|
|
}
|
|
|
|
}
|
|
}
|