Skip to content

Commit c589d30

Browse files
committed
Fix
1 parent 62af038 commit c589d30

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/lib.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use actix_web_httpauth::middleware::HttpAuthentication;
66
use futures::{future, Future};
77
use rand::distributions::Alphanumeric;
88
use rand::{thread_rng, Rng};
9-
use serde::Deserialize;
109
use std::error::Error;
1110
use std::fs;
1211
use std::fs::OpenOptions;
@@ -78,11 +77,8 @@ fn new_paste(
7877
) -> impl Future<Item = HttpResponse, Error = form_data::Error> {
7978
form_data::handle_multipart(mp, form.get_ref().clone()).map(move |form_value| {
8079
let paste = match form_value {
81-
form_data::Value::Map(mut form_map) => match form_map.remove("paste") {
82-
Some(paste) => paste.text().unwrap(),
83-
None => return HttpResponse::InternalServerError().into(),
84-
},
85-
_ => return HttpResponse::InternalServerError().into(),
80+
form_data::Value::Map(mut form_map) => form_map.remove("paste")?.text()?,
81+
_ => return None,
8682
};
8783

8884
let mut rng = thread_rng();
@@ -101,15 +97,18 @@ fn new_paste(
10197
}
10298
};
10399

104-
let paste_url = format!("{}/{}", config.url_base, paste_id);
100+
file.write_all(paste.as_bytes()).ok()?;
105101

106-
match file.write_all(paste.as_bytes()) {
107-
Ok(_) => HttpResponse::Created()
108-
.set_header("Location", paste_url.clone())
109-
.content_type("text/plain")
110-
.body(paste_url),
111-
Err(_) => HttpResponse::InternalServerError().into(),
112-
}
102+
let paste_url = format!("{}/{}", config.url_base, paste_id);
103+
Some(HttpResponse::Created()
104+
.set_header("Location", paste_url.clone())
105+
.content_type("text/plain")
106+
.body(paste_url))
107+
})
108+
.map(|res| match res {
109+
Some(response) => response,
110+
// TODO: Add info to error response.
111+
None => HttpResponse::InternalServerError().finish(),
113112
})
114113
}
115114

0 commit comments

Comments
 (0)