chiark / gitweb /
actix: Log an error if we have an internal server error
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 26 Mar 2022 22:53:57 +0000 (22:53 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Mar 2022 23:50:50 +0000 (00:50 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
daemon/main.rs

index 1337b7a783616423bd0f3060e93aabf3596b11cb..4ec910f645a1aa16674d236076f2df898ca4b18e 100644 (file)
@@ -90,9 +90,7 @@ impl ResponseError for FatalErrorResponse {
   }
 
   fn error_response(&self) -> HttpResponse<BoxBody> {
-    self.status_code().respond_text(
-      &format_args!("Online-layer error\n{:?}\n{}\n", self, self)
-    )
+    error_response(self)
   }
 }
 
index 9ea649e0051eab392d81d2d4013c2d7a79bb5d5c..fca559f0ac889e34f33e36b783b57c951432ce0c 100644 (file)
@@ -317,6 +317,10 @@ impl ResponseError for BundleDownloadError {
       BDE::IE(_)               => StatusCode::INTERNAL_SERVER_ERROR,
     }
   }
+
+  fn error_response(&self) -> HttpResponse<BoxBody> {
+    error_response(self)
+  }
 }
 
 #[route("/_/bundle/{instance}/{id}", method="GET", method="HEAD")]
@@ -407,6 +411,18 @@ async fn not_found_handler(method: Method) -> impl Responder {
   }
 }
 
+fn error_response<E>(self_: &E) -> HttpResponse<BoxBody>
+where E: ResponseError + Debug + Display
+{
+  let status = self_.status_code();
+  if status == StatusCode::INTERNAL_SERVER_ERROR {
+    error!("responding with internal error -- {} -- {:?}", self_, self_);
+  }
+  self_.status_code().respond_text(
+    &format_args!("{}\n{:?}\n", self_, self_)
+  )
+}
+
 #[actix_web::main] // not compatible with fehler
 async fn main() -> Result<(),StartupError> {
   use structopt::StructOpt;