From 57c9da7f6bc98fb70e26f5332ffccfd55f7eb69b Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 11 Mar 2020 18:38:22 +0800 Subject: ... --- Timeline/Controllers/TimelineController.cs | 15 +++++++++++++-- Timeline/Models/Http/ErrorResponse.cs | 10 ++++++++++ Timeline/Resources/Messages.Designer.cs | 9 +++++++++ Timeline/Resources/Messages.resx | 3 +++ 4 files changed, 35 insertions(+), 2 deletions(-) (limited to 'Timeline') diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index 0628937d..6e5438c4 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -123,8 +123,19 @@ namespace Timeline.Controllers return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); } - var data = await _service.GetPostData(name, id); - return File(data.Data, data.Type, data.LastModified, new EntityTagHeaderValue(data.ETag)); + try + { + var data = await _service.GetPostData(name, id); + return File(data.Data, data.Type, data.LastModified, new EntityTagHeaderValue(data.ETag)); + } + catch (TimelinePostNotExistException) + { + return NotFound(ErrorResponse.TimelineController.PostNotExist()); + } + catch (InvalidOperationException) + { + return BadRequest(ErrorResponse.TimelineController.PostNoData()); + } } [HttpPost("timelines/{name}/posts")] diff --git a/Timeline/Models/Http/ErrorResponse.cs b/Timeline/Models/Http/ErrorResponse.cs index 9c5a7cfe..bb9c44df 100644 --- a/Timeline/Models/Http/ErrorResponse.cs +++ b/Timeline/Models/Http/ErrorResponse.cs @@ -285,6 +285,16 @@ namespace Timeline.Models.Http return new CommonResponse(ErrorCodes.TimelineController.QueryRelateNotExist, string.Format(message, formatArgs)); } + public static CommonResponse PostNotExist(params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineController.PostNotExist, string.Format(TimelineController_PostNotExist, formatArgs)); + } + + public static CommonResponse CustomMessage_PostNotExist(string message, params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineController.PostNotExist, string.Format(message, formatArgs)); + } + public static CommonResponse PostNoData(params object?[] formatArgs) { return new CommonResponse(ErrorCodes.TimelineController.PostNoData, string.Format(TimelineController_PostNoData, formatArgs)); diff --git a/Timeline/Resources/Messages.Designer.cs b/Timeline/Resources/Messages.Designer.cs index cae91093..40c4a1ce 100644 --- a/Timeline/Resources/Messages.Designer.cs +++ b/Timeline/Resources/Messages.Designer.cs @@ -222,6 +222,15 @@ namespace Timeline.Resources { } } + /// + /// Looks up a localized string similar to The post to operate on does not exist.. + /// + internal static string TimelineController_PostNotExist { + get { + return ResourceManager.GetString("TimelineController_PostNotExist", resourceCulture); + } + } + /// /// Looks up a localized string similar to The user specified by query param "relate" does not exist.. /// diff --git a/Timeline/Resources/Messages.resx b/Timeline/Resources/Messages.resx index 631bd749..8d5543fe 100644 --- a/Timeline/Resources/Messages.resx +++ b/Timeline/Resources/Messages.resx @@ -171,6 +171,9 @@ The post of that type has no data. + + The post to operate on does not exist. + The user specified by query param "relate" does not exist. -- cgit v1.2.3