I am still not sure how to construct a rejection. When i start with
if error { return Err(warp::reject::not_found()) }
the compiler complains:
the trait std::clone::Clone is not implemented for warp::reject::Rejection
the trait warp::filter::FilterBase is not implemented for std::result::Result<_, warp::reject::Rejection>
What is the best way to construct a Filter that returns a JSON error string and HTTP error code?
Wow, the documentation is not easy to follow, things that appear to be central important types such as FilterBase appear to be completely hidden from the documentation. Even after cloning warp locally and building with --document-private-items, I still couldn't figure out how things fit together.
It seems like you shouldn't be returning Err, but I can't tell what you should be using to wrap the rejection instead.
Thank you. I agree that there are some gaps in warp's documentation.
I am also sad that the traits in the return types do not work well together with todo!() or unimplemented!().
But warp is basically a one man show and Sean is insanely productive across many important projects.
So i try to get comfortable using warp and maybe contribute to its documentation later on, but all this without diverting Sean's energy too much.
Rejections are meant to say a Filter couldn't fulfill its preconditions, but maybe another Filter can. If a filter is otherwise fully matched, and an error occurs in your business logic, it's probably not correct to reject with the error. In that case, you'd want to construct a Reply that describes your error.