diff options
author | 杨宇千 <crupest@outlook.com> | 2019-11-07 22:06:06 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-11-07 22:06:06 +0800 |
commit | 5f9f9a9e40306f83bf360c3d27e4e33e78565fce (patch) | |
tree | 48ca95c6eb5dafe44d419bbe5d0ab49396209b13 /Timeline/Filters | |
parent | 9df5a86786ac2dcb8bc0f34f69501abfffd0dc9c (diff) | |
download | timeline-5f9f9a9e40306f83bf360c3d27e4e33e78565fce.tar.gz timeline-5f9f9a9e40306f83bf360c3d27e4e33e78565fce.tar.bz2 timeline-5f9f9a9e40306f83bf360c3d27e4e33e78565fce.zip |
Complete PersonalTimelineController and write attribute test.
Diffstat (limited to 'Timeline/Filters')
-rw-r--r-- | Timeline/Filters/Timeline.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Timeline/Filters/Timeline.cs b/Timeline/Filters/Timeline.cs new file mode 100644 index 00000000..7859d409 --- /dev/null +++ b/Timeline/Filters/Timeline.cs @@ -0,0 +1,47 @@ +using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Filters;
+using Timeline.Models.Http;
+using Timeline.Services;
+using static Timeline.Resources.Filters;
+
+namespace Timeline
+{
+ public static partial class ErrorCodes
+ {
+ public static partial class Http
+ {
+ public static partial class Filter // bxx = 1xx
+ {
+ public static class Timeline // bbb = 102
+ {
+ public const int UserNotExist = 11020101;
+ public const int NameNotExist = 11020102;
+ }
+ }
+ }
+ }
+}
+
+namespace Timeline.Filters
+{
+ public class CatchTimelineNotExistExceptionAttribute : ExceptionFilterAttribute
+ {
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods")]
+ public override void OnException(ExceptionContext context)
+ {
+ if (context.Exception is TimelineNotExistException e)
+ {
+ if (e.InnerException is UserNotExistException)
+ {
+ context.Result = new BadRequestObjectResult(
+ new CommonResponse(ErrorCodes.Http.Filter.Timeline.UserNotExist, MessageTimelineNotExistUser));
+ }
+ else
+ {
+ context.Result = new BadRequestObjectResult(
+ new CommonResponse(ErrorCodes.Http.Filter.Timeline.NameNotExist, MessageTimelineNotExist));
+ }
+ }
+ }
+ }
+}
|