Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make libworker::Error public and non-exhaustive #19

Closed
wants to merge 2 commits into from
Closed

Conversation

jyn514
Copy link
Contributor

@jyn514 jyn514 commented Aug 25, 2021

Making it public allows users to handle errors themselves.
Making it non-exhaustive allows us to add more error variants in the future without needing a breaking change.

Fixes #11

@nilslice
Copy link
Contributor

This is a good idea, but I don't think it's actually complete.. could you try to deploy and test the running rust-sandbox worker? you can delete the routes that use the bindings in wrangler.toml, or create them and modify the IDs.

Making it public allows users to handle errors themselves.

Based on the code in Request::json , i don't think there's enough to prove the example you added works:

/// # use libworker::{Error, Response, Router};
/// let mut router = Router::new();
/// let result: Result<(), Error> = router.post_async("/my_json_api", |mut req, env, _params| async move {
///     let input = match req.json().await {
///         Ok(j) => j,
///         Err(Error::BadEncoding) => return Response::error("POST body must be JSON", 400),
///         Err(other_err) => return Err(other_err),
///     };
///     Response::ok("{}")
/// });

jyn514 and others added 2 commits August 27, 2021 23:12
Making it public allows users to handle errors themselves.
Making it non-exhaustive allows us to add more error variants in the future without needing a breaking change.
@nilslice
Copy link
Contributor

Closing this as it was done in another branch. Thanks!

@nilslice nilslice closed this Aug 30, 2021
@jyn514 jyn514 deleted the jnelson/error branch August 30, 2021 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make worker::Error public
2 participants