diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-05 19:54:15 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-05 19:54:15 +0200 |
commit | 6f04a7e1547a8daf535525f9c4aa7145862a8a51 (patch) | |
tree | 10f7598f2ab9593f08790f0768c3cc7d25e34007 | |
parent | ab8f8c1fa5e44c8249f5e4df20c9fcc23b9fe2e2 (diff) | |
download | askama-6f04a7e1547a8daf535525f9c4aa7145862a8a51.tar.gz askama-6f04a7e1547a8daf535525f9c4aa7145862a8a51.tar.bz2 askama-6f04a7e1547a8daf535525f9c4aa7145862a8a51.zip |
Raise 500 error instead of unwrapping in Rocket Responder impl
-rw-r--r-- | askama_shared/src/generator.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index a7fba18..3194cd9 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -696,16 +696,20 @@ impl<'a> Generator<'a> { self.writeln("fn respond_to(self, _: &::askama::rocket::Request) \ -> ::std::result::Result<\ ::askama::rocket::Response<'r>, ::askama::rocket::Status> {"); + self.writeln("let rsp = self.render().map_err(\ + |_| ::askama::rocket::Status::InternalServerError)?;"); + + self.writeln("::askama::rocket::Response::build()"); + self.indent(); let ext = match path.extension() { Some(s) => s.to_str().unwrap(), None => "txt", }; - self.writeln("::askama::rocket::Response::build()"); - self.indent(); self.writeln(&format!(".header(::askama::rocket::ContentType::from_extension({:?})\ .unwrap())", ext)); - self.writeln(".sized_body(::std::io::Cursor::new(self.render().unwrap()))"); + self.writeln(".sized_body(::std::io::Cursor::new(rsp))"); self.writeln(".ok()"); + self.dedent(); self.writeln("}"); self.writeln("}"); |