summaryrefslogtreecommitdiffstats
path: root/ipfs-api/src/header.rs
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2017-11-25 12:11:09 -0500
committerFerris Tseng <ferristseng@fastmail.fm>2017-11-25 12:11:09 -0500
commitbe4d9527b0ee4830d5434e6e70415d2f18af0180 (patch)
treebfcdd03b4df19c5148cdc35dd26f345e8e5f6bb3 /ipfs-api/src/header.rs
parentb2ba32dcd849732d62eaed5940f5db5367e42fe1 (diff)
handle streaming errors
Diffstat (limited to 'ipfs-api/src/header.rs')
-rw-r--r--ipfs-api/src/header.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/ipfs-api/src/header.rs b/ipfs-api/src/header.rs
index 32941cc..486be0c 100644
--- a/ipfs-api/src/header.rs
+++ b/ipfs-api/src/header.rs
@@ -42,3 +42,29 @@ impl Header for Trailer {
f.fmt_line(&value)
}
}
+
+
+#[derive(Debug, Clone)]
+pub struct XStreamError {
+ pub error: String,
+}
+
+impl Header for XStreamError {
+ fn header_name() -> &'static str {
+ "X-Stream-Error"
+ }
+
+ fn parse_header(raw: &Raw) -> hyper::Result<XStreamError> {
+ if let Some(bytes) = raw.one() {
+ let value = String::from_utf8_lossy(bytes);
+
+ Ok(XStreamError { error: value.into_owned() })
+ } else {
+ Err(hyper::Error::Header)
+ }
+ }
+
+ fn fmt_header(&self, f: &mut header::Formatter) -> fmt::Result {
+ f.fmt_line(&self.error)
+ }
+}