about summary refs log tree commit diff
path: root/src/errors.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2018-05-26T08·53+0200
committerVincent Ambo <github@tazj.in>2018-05-27T13·00+0200
commita14ece6af3a2d0f03af072c337ef50e311a79066 (patch)
tree91959834f373f9f3c486609199af99db26127644 /src/errors.rs
parentc2a551146d04e5e69192cdf3799684f2f9be5104 (diff)
feat(errors): Introduce error variant for thread closing
(other minor change: log the user ID when invalid post editing
requests were constructed)
Diffstat (limited to 'src/errors.rs')
-rw-r--r--src/errors.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/errors.rs b/src/errors.rs
index 3f00a2976a2a..c73379f0cafb 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -56,8 +56,11 @@ pub enum ConverseError {
     #[fail(display = "error occured running timer: {}", error)]
     Timer { error: tokio_timer::Error },
 
-    #[fail(display = "user does not have permission to edit post {}", id)]
-    PostEditForbidden { id: i32 },
+    #[fail(display = "user {} does not have permission to edit post {}", user, id)]
+    PostEditForbidden { user: i32, id: i32 },
+
+    #[fail(display = "thread {} is closed and can not be responded to", id)]
+    ThreadClosed { id: i32 },
 
     // This variant is used as a catch-all for wrapping
     // actix-web-compatible response errors, such as the errors it
@@ -119,7 +122,12 @@ impl From<tokio_timer::Error> for ConverseError {
 impl ResponseError for ConverseError {
     fn error_response(&self) -> HttpResponse {
         // Everything is mapped to internal server errors for now.
-        HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR)
-            .body(format!("An error occured: {}", self))
+        match *self {
+            ConverseError::ThreadClosed { id } => HttpResponse::SeeOther()
+                .header("Location", format!("/thread/{}#edit-post", id))
+                .finish(),
+            _ => HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR)
+                .body(format!("An error occured: {}", self))
+        }
     }
 }