nickel-org / nickel.rs

An expressjs inspired web framework for Rust

Home Page:http://nickel-org.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error handling example

flosse opened this issue · comments

It would be great to have an example with proper error handling.
E.g. how can I use a custom AppError within my routes? I'd like to write something like

fn post_foo<'a>(req: &mut nickel::Request<Data>,
                          res: nickel::Response<'a,Data>)
                          -> MiddlewareResult<'a,Data> {
  let db = res.server_data().db.clone();
  let foo = try!(something(&pool));
  let bar = try!(precedure(&foo));
  try!(baz(bar))
}

Each of the methods return a AppError and somewhere central would be a custom mapping of the HTTP status codes and error messages. How can I achieve this?

In #304 I started with an example that needs to be improved. Could you help me?

Left a comment on the PR :)