Abp中自定义Exception的HttpStatusCode


/// <summary>
/// 自定义错误状态吗
/// </summary>
public class CustomeException : UserFriendlyException
{
public CustomeException(int code, string message, string details)
: this((int)HttpStatusCode.BadRequest, code, message, details)
{
} public CustomeException(HttpStatusCode httpCode, int code, string message, string details)
: this((int)httpCode, code, message, details)
{
} public CustomeException(int httpCode, int code, string message, string details)
: base(code, message, details)
{
HttpCode = httpCode;
}
/// <summary>
/// http 状态码
/// </summary>
public int HttpCode { get; set; }
}
public class CustomeApiExceptionFilterAttribute : AbpApiExceptionFilterAttribute, ITransientDependency
{
public CustomeApiExceptionFilterAttribute(IAbpWebApiConfiguration configuration) : base(configuration)
{
} protected override HttpStatusCode GetStatusCode(HttpActionExecutedContext context)
{
var customException = (context.Exception as CustomeException);
if (customException != null)
{
return
(HttpStatusCode)customException.HttpCode;
}
else
{
return base.GetStatusCode(context);
}
} public void UseThis()
{
var filters = Configuration.HttpConfiguration.Filters;
var filterInfo = filters.FirstOrDefault(h => h.Instance is AbpApiExceptionFilterAttribute);
if (filterInfo != null) {
filters.Remove(filterInfo.Instance);
} filters.Add(this);
}
}


Abp中自定义Exception的HttpStatusCode的更多相关文章
- ABP中的拦截器之ValidationInterceptor(下)
在上篇我分析了整个ABP中ValitationInterceptor的整个过程,就其中涉及到的Validator过程没有详细的论述,这篇文章就这个过程进行详细的论述,另外任何一个重要的特性如何应用是最 ...
- ABP中的Filter(下)
接着上面的一个部分来叙述,这一篇我们来重点看ABP中的AbpUowActionFilter.AbpExceptionFilter.AbpResultFilter这三个部分也是按照之前的思路来一个个介绍 ...
- ABP中的Filter(上)
这个部分我打算用上下两个部分来将整个结构来讲完,在我们读ABP中的代码之后我们一直有一个疑问?在ABP中为什么要定义Interceptor和Filter,甚至这两者之间我们都能找到一些对应关系,比如: ...
- ABP源码分析四十七:ABP中的异常处理
ABP 中异常处理的思路是很清晰的.一共五种类型的异常类. AbpInitializationException用于封装ABP初始化过程中出现的异常,只要抛出AbpInitializationExce ...
- ABP中的拦截器之AuditingInterceptor
在上面两篇介绍了ABP中的ValidationInterceptor之后,我们今天来看看ABP中定义的另外一种Interceptor即为AuditingInterceptor,顾名思义就是一种审计相关 ...
- ABP中的拦截器之ValidationInterceptor(上)
从今天这一节起就要深入到ABP中的每一个重要的知识点来一步步进行分析,在进行介绍ABP中的拦截器之前我们先要有个概念,到底什么是拦截器,在介绍这些之前,我们必须要了解AOP编程思想,这个一般翻译是面向 ...
- ABP源码分析三十五:ABP中动态WebAPI原理解析
动态WebAPI应该算是ABP中最Magic的功能之一了吧.开发人员无须定义继承自ApiController的类,只须重用Application Service中的类就可以对外提供WebAPI的功能, ...
- ABP中使用Redis Cache(1)
本文将讲解如何在ABP中使用Redis Cache以及使用过程中遇到的各种问题.下面就直接讲解使用步骤,Redis环境的搭建请直接网上搜索. 使用步骤: 一.ABP环境搭建 到http://www.a ...
- ABP中动态WebAPI原理解析
ABP中动态WebAPI原理解析 动态WebAPI应该算是ABP中最Magic的功能之一了吧.开发人员无须定义继承自ApiController的类,只须重用Application Service中的类 ...
随机推荐
- Python12/25--前端之BOM/DOM
一.DOM 1. 什么是DOM 文档对象模型 Document Object Model 文档对象模型 是表示和操作 HTML和XML文档内容的基础API 文档对象模型,是W3C组织推荐的处理可扩展标 ...
- Python12/11--盒子的显隐/布局/z-index/流式布局思想
1.盒子的显隐 display:none 在页面中不占位,采用定位布局后,显示隐藏都不会影响其他标签,不需要用动画处理时,一般用这个 opacoity : 0 在页面中占位,采 ...
- tomcat是否有必要配置环境变量(摘)
之前发表了一篇关于如何安装和配置Tomcat的文章,而最近在开发项目的时候总是报错.后来被公司的大神问了一句:是谁告诉你Tomcat是需要配置环境变量的? 作为新手的我瞬间整个人都不好了!于是偷偷百度 ...
- Noxim配置运行
Noxim - the NoC Simulator that is implemented by SystemC 第一步: C++ compiler installation 第二步: YAML in ...
- xml配置文件中常见的命名空间解释
1.1schema文档即xml schema document,schema文件的格式是.xsd(xml schema document的缩写xsd). 简单来说:schema就是对xml的进一步约束 ...
- 简介jsp
1.JSP简介 Java动态网页技术标准(Java Server Pages)是基于Servlet技术以及整个Java体系的Web开发技术是用于动态生成HTML文档的Web页面模板JSP是为了改进Se ...
- 583. Delete Operation for Two Strings
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...
- cad.net 更改高版本填充交互方式为低版本样子
/// <summary> /// 修改cui,双击填充 /// </summary> /// https://blog.csdn.net/hfmwu/article/deta ...
- Spring Boot定制启动图案
启动图案 Spring Boot在启动的时候会显示一个默认的Spring的图案,对应的类为SpringBootBanner. . ____ _ __ _ _ /\\ / ___'_ __ _ _(_) ...
- Hbase shell基本操作
1.启动cd <hbase_home>/bin$ ./start-hbase.sh 2.启动hbase shell # find hadoop-hbase dfs fileshadoop ...