aboutsummaryrefslogtreecommitdiffstats
path: root/license-generator/src/bin/license.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-11-13 05:39:15 +0100
committerTeddy Wing2018-11-13 05:39:15 +0100
commite8f8a6737f6b3a612d6243be94e98dde7071859f (patch)
tree813fe34e898bacaa6828988aa09fa2363f32b0ce /license-generator/src/bin/license.rs
parentb02f3aac30557167f8f81c1294094426c34a2c35 (diff)
downloaddome-key-web-e8f8a6737f6b3a612d6243be94e98dde7071859f.tar.bz2
license: Remove `unwrap`s
Respond with a 500 on error. Add 'aquatic-prime' to `foreign_links` errors to be able to convert it with `into()`.
Diffstat (limited to 'license-generator/src/bin/license.rs')
-rw-r--r--license-generator/src/bin/license.rs35
1 files changed, 31 insertions, 4 deletions
diff --git a/license-generator/src/bin/license.rs b/license-generator/src/bin/license.rs
index aac7ef5..502f98e 100644
--- a/license-generator/src/bin/license.rs
+++ b/license-generator/src/bin/license.rs
@@ -136,17 +136,44 @@ fn main() -> Result<()> {
let email = email.unwrap().to_string();
let secret = secret.unwrap().to_string();
- let purchaser = query_purchaser(&mut cx, &name, &email, &secret).unwrap();
- if purchaser.is_some() {
+ let purchaser = match query_purchaser(&mut cx, &name, &email, &secret) {
+ Ok(p) => p,
+ Err(e) => return response::error_500(
+ &mut req.stdout(),
+ Some(e.into())
+ ),
+ };
+
+ if let Some(purchaser) = purchaser {
+ match purchaser {
+ Ok(p) => p,
+ Err(e) => return response::error_500(
+ &mut req.stdout(),
+ Some(e.into())
+ ),
+ };
+
let license_data = LicenseData {
name: &name,
email: &email,
};
- let license = aquatic_prime.plist(license_data).unwrap();
+ let license = match aquatic_prime.plist(license_data) {
+ Ok(p) => p,
+ Err(e) => return response::error_500(
+ &mut req.stdout(),
+ Some(e.into())
+ ),
+ };
let mut zip_data = Cursor::new(vec![]);
- zip::license(&mut zip_data, license.as_bytes()).unwrap();
+ match zip::license(&mut zip_data, license.as_bytes()) {
+ Ok(p) => p,
+ Err(e) => return response::error_500(
+ &mut req.stdout(),
+ Some(e.into())
+ ),
+ }
write!(&mut req.stdout(), "Content-Type: application/zip
Content-Disposition: attachment; filename=\"dome-key-license.zip\"\n\n")