aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Filters
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-10-28 23:35:00 +0800
committer杨宇千 <crupest@outlook.com>2019-10-28 23:35:00 +0800
commit006d799d2fe5f081c188f95a8590c4b75a93caae (patch)
tree97ed1fa767e1492cd3df292247d8fd3e47252882 /Timeline/Filters
parentc11a1b7be5d41bb1825a7190c708fdb04923a4fd (diff)
downloadtimeline-006d799d2fe5f081c188f95a8590c4b75a93caae.tar.gz
timeline-006d799d2fe5f081c188f95a8590c4b75a93caae.tar.bz2
timeline-006d799d2fe5f081c188f95a8590c4b75a93caae.zip
Add UserDetailController unit tests.
Diffstat (limited to 'Timeline/Filters')
-rw-r--r--Timeline/Filters/User.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/Timeline/Filters/User.cs b/Timeline/Filters/User.cs
new file mode 100644
index 00000000..22fae938
--- /dev/null
+++ b/Timeline/Filters/User.cs
@@ -0,0 +1,42 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Filters;
+using System;
+using Timeline.Models.Http;
+
+namespace Timeline
+{
+ public static partial class ErrorCodes
+ {
+ public static partial class Http
+ {
+ public static partial class Filter // bxx = 1xx
+ {
+ public static class User // bbb = 101
+ {
+ public const int NotExist = 11010001;
+ }
+
+ }
+ }
+ }
+}
+
+namespace Timeline.Filters
+{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
+ public class CatchUserNotExistExceptionAttribute : ExceptionFilterAttribute
+ {
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "ASP.Net already checked.")]
+ public override void OnException(ExceptionContext context)
+ {
+ var body = new CommonResponse(
+ ErrorCodes.Http.Filter.User.NotExist,
+ Resources.Filters.MessageUserNotExist);
+
+ if (context.HttpContext.Request.Method == "GET")
+ context.Result = new NotFoundObjectResult(body);
+ else
+ context.Result = new BadRequestObjectResult(body);
+ }
+ }
+}