aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2017-11-11 22:29:03 +0100
committerTeddy Wing2017-11-11 22:29:03 +0100
commit7b62d76be439e11db52933d9f168d6f3ac5691c5 (patch)
tree58a6670fb042693aebfadcbb643acdb8cccef254 /src/main.rs
parent3f21e05778261f8d1d7ca382ec73da1a3801537d (diff)
downloadkipper-7b62d76be439e11db52933d9f168d6f3ac5691c5.tar.bz2
main(): Handle errors from `Result`s
Now that our functions return `Result`s for errors instead of panicking, we need to handle these errors. For now, just respond with a 500. We'll also want to log the errors though.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index e5f7235..5882909 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,6 +8,11 @@ use std::io::Read;
use kipper::jenkins;
use kipper::pull_request::CommitRef;
+fn internal_server_error() -> rouille::Response {
+ rouille::Response::text("500 Internal Server Error")
+ .with_status_code(500)
+}
+
fn main() {
rouille::start_server("localhost:8000", move |request| {
router!(request,
@@ -20,9 +25,15 @@ fn main() {
Some(mut data) => {
try_or_400!(data.read_to_string(&mut body));
- let commit_ref = CommitRef::new(body.as_ref());
+ let commit_ref = match CommitRef::new(body.as_ref()) {
+ Ok(cr) => cr,
+ Err(_) => return internal_server_error(),
+ };
- jenkins::find_and_track_build_and_update_status(commit_ref);
+ match jenkins::find_and_track_build_and_update_status(commit_ref) {
+ Ok(_) => {},
+ Err(_) => return internal_server_error(),
+ };
rouille::Response::text("202 Accepted")
.with_status_code(202)