aboutsummaryrefslogtreecommitdiffstats
path: root/license-generator/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-11-11 02:11:36 +0100
committerTeddy Wing2018-11-11 02:11:36 +0100
commitedf6fceedd9b4169ceb63172c60733ef84d78951 (patch)
tree5ff59d7708ad13b68d8a211b10d283a5c9dd972c /license-generator/src/main.rs
parenta9f405988052a49ad3ebbe2a5b1f0db80036b2cd (diff)
downloaddome-key-web-edf6fceedd9b4169ceb63172c60733ef84d78951.tar.bz2
main(): Extract 500 errors to a function
Clean up the `main()` function by extracting all these similar lines to a function.
Diffstat (limited to 'license-generator/src/main.rs')
-rw-r--r--license-generator/src/main.rs54
1 files changed, 11 insertions, 43 deletions
diff --git a/license-generator/src/main.rs b/license-generator/src/main.rs
index 8e60d51..f2beb26 100644
--- a/license-generator/src/main.rs
+++ b/license-generator/src/main.rs
@@ -87,13 +87,7 @@ fn main() -> Result<()> {
}
},
None => {
- response::set_500(&mut req.stdout()).unwrap_or(());
- write!(&mut req.stdout(), "Content-Type: text/plain
-
-500 Internal Server Error")
- .unwrap_or(());
-
- return;
+ return response::error_500(&mut req.stdout(), None);
},
};
@@ -101,15 +95,7 @@ fn main() -> Result<()> {
let is_verified = match request::verified(&ps) {
Ok(v) => v,
Err(e) => {
- error!("{}", e);
-
- response::set_500(&mut req.stdout()).unwrap_or(());
- write!(&mut req.stdout(), "Content-Type: text/plain
-
-500 Internal Server Error")
- .unwrap_or(());
-
- return;
+ return response::error_500(&mut req.stdout(), Some(e));
},
};
@@ -123,15 +109,10 @@ fn main() -> Result<()> {
let mut cx = match pool.get_conn() {
Ok(cx) => cx,
Err(e) => {
- error!("{}", e);
-
- response::set_500(&mut req.stdout()).unwrap_or(());
- write!(&mut req.stdout(), "Content-Type: text/plain
-
-500 Internal Server Error")
- .unwrap_or(());
-
- return;
+ return response::error_500(
+ &mut req.stdout(),
+ Some(e.into())
+ );
},
};
@@ -147,28 +128,15 @@ fn main() -> Result<()> {
return;
},
Err(e) => {
- error!("{}", e);
-
- response::set_500(&mut req.stdout()).unwrap_or(());
- write!(&mut req.stdout(), "Content-Type: text/plain
-
-500 Internal Server Error")
- .unwrap_or(());
-
- return;
+ return response::error_500(&mut req.stdout(), Some(e));
},
}
}
- error!("Purchaser name or email not set");
-
- response::set_500(&mut req.stdout()).unwrap_or(());
- write!(&mut req.stdout(), "Content-Type: text/plain
-
-500 Internal Server Error")
- .unwrap_or(());
-
- return;
+ return response::error_500(
+ &mut req.stdout(),
+ Some("Purchaser name or email not set".into())
+ );
}
response::set_403(&mut req.stdout()).unwrap_or(());