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中的类 ...
随机推荐
- Effective C++ 笔记:条款 30 inline
30 : Understand the ins and outs of inlining 1 inline申请书 1.1 类内部实现函数包含隐藏的inline申请 class Human { publ ...
- boost--时间处理
date_time库的时间功能位于名字空间boost::posix_time,它提供了微妙级别(最高可达纳秒)的时间系统,使用需要包含头文件"boost\date_time\posix_ti ...
- GitHub上好的Java项目
1. java-design-patterns(Star:36k)Github地址:https://github.com/iluwatar/java-design-patterns 介绍:设计模式是形 ...
- Nginx+Django搭建
本机环境介绍 虚拟机操作系统版本如下 [root@node1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) IP地址 ...
- HPS基本概念及其设计
DE1-SOC开发版上的FPGA在一个基于ARM的用户定制系统(SOC)中集成了分立处理器(HPS).FPGA和数字信号处理(DSP)功能.HPS是基于ARM cortex-A9双核处理器,具有丰富的 ...
- pb数据导出
pb数据导出(一) 1.在窗口新建用户事件 ue_export 2.事件调用函数 gf_dw_to_excel(THIS.dw_dict) 3.写函数 :boolean lb_setborde ...
- Baidu WebUploader 前端文件上传组件的使用
简介 WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件.在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流I ...
- 第十节:详细讲解一下Java多线程,随机文件
前言 大家好,给大家带来第十节:详细讲解一下Java多线程,随机文件的概述,希望你们喜欢 多线程的概念 线程的生命周期 多线程程序的设计 多线程的概念 多线程的概念:程序是静态的,进程是动态的.多进程 ...
- 课程四(Convolutional Neural Networks),第一周(Foundations of Convolutional Neural Networks) —— 0.Learning Goals
Learning Goals Understand the convolution operation Understand the pooling operation Remember the vo ...
- MySQL笔记(8)---备份与恢复
1.前言 本章记录数据库的备份与恢复操作.MySQL提供了很多工具完成备份工作:mysqldump.ibbackup.replication,也可以使用一些第三方的工具完成,如xtrabacup.LV ...