diff options
Diffstat (limited to 'Timeline')
-rw-r--r-- | Timeline/Controllers/TimelineController.cs | 15 | ||||
-rw-r--r-- | Timeline/Models/Http/ErrorResponse.cs | 10 | ||||
-rw-r--r-- | Timeline/Resources/Messages.Designer.cs | 9 | ||||
-rw-r--r-- | Timeline/Resources/Messages.resx | 3 |
4 files changed, 35 insertions, 2 deletions
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 @@ -223,6 +223,15 @@ namespace Timeline.Resources { }
/// <summary>
+ /// Looks up a localized string similar to The post to operate on does not exist..
+ /// </summary>
+ internal static string TimelineController_PostNotExist {
+ get {
+ return ResourceManager.GetString("TimelineController_PostNotExist", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to The user specified by query param "relate" does not exist..
/// </summary>
internal static string TimelineController_QueryRelateNotExist {
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 @@ <data name="TimelineController_PostNoData" xml:space="preserve">
<value>The post of that type has no data.</value>
</data>
+ <data name="TimelineController_PostNotExist" xml:space="preserve">
+ <value>The post to operate on does not exist.</value>
+ </data>
<data name="TimelineController_QueryRelateNotExist" xml:space="preserve">
<value>The user specified by query param "relate" does not exist.</value>
</data>
|