Skip to content

Commit

Permalink
when an upstream body is unexpectedly closed, return Httpincomplete
Browse files Browse the repository at this point in the history
This is better than a generic error, and matches the C@E behavior.

Fixes #289.
  • Loading branch information
joeshaw committed Jul 20, 2023
1 parent 7a8e569 commit 522c74e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Error types.
use std::error::Error as StdError;
use std::io;
use {crate::wiggle_abi::types::FastlyStatus, url::Url, wiggle::GuestError};

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -153,6 +155,14 @@ impl Error {
Error::HyperError(e) if e.is_parse() => FastlyStatus::Httpinvalid,
Error::HyperError(e) if e.is_user() => FastlyStatus::Httpuser,
Error::HyperError(e) if e.is_incomplete_message() => FastlyStatus::Httpincomplete,
Error::HyperError(e)
if e.source()
.and_then(|e| e.downcast_ref::<io::Error>())
.map(|ioe| ioe.kind())
== Some(io::ErrorKind::UnexpectedEof) =>
{
FastlyStatus::Httpincomplete
}
Error::HyperError(_) => FastlyStatus::Error,
// Destructuring a GuestError is recursive, so we use a helper function:
Error::GuestError(e) => Self::guest_error_fastly_status(e),
Expand Down

0 comments on commit 522c74e

Please sign in to comment.