Commit 7ff0e8a 1 parent 6871bae commit 7ff0e8a Copy full SHA for 7ff0e8a
File tree 4 files changed +25
-10
lines changed
4 files changed +25
-10
lines changed Original file line number Diff line number Diff line change 1
1
# Unreleased
2
2
3
- * send_json should set content-length header (#983 )
3
+ * ureq::Error wrapped as io::Error should pass through body chain (#984 )
4
+ * send_json should set content-length header (#983 )
4
5
5
6
# 3.0.4
6
7
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use std::io;
2
2
3
3
use brotli_decompressor:: Decompressor ;
4
4
5
+ use crate :: error:: is_wrapped_ureq_error;
5
6
use crate :: Error ;
6
7
7
8
pub ( crate ) struct BrotliDecoder < R : io:: Read > ( Decompressor < R > ) ;
@@ -14,8 +15,13 @@ impl<R: io::Read> BrotliDecoder<R> {
14
15
15
16
impl < R : io:: Read > io:: Read for BrotliDecoder < R > {
16
17
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
17
- self . 0
18
- . read ( buf)
19
- . map_err ( |e| Error :: Decompress ( "brotli" , e) . into_io ( ) )
18
+ self . 0 . read ( buf) . map_err ( |e| {
19
+ if is_wrapped_ureq_error ( & e) {
20
+ // If this already is a ureq::Error, like Timeout, pass it along.
21
+ e
22
+ } else {
23
+ Error :: Decompress ( "brotli" , e) . into_io ( )
24
+ }
25
+ } )
20
26
}
21
27
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use std::io;
2
2
3
3
use flate2:: read:: MultiGzDecoder ;
4
4
5
+ use crate :: error:: is_wrapped_ureq_error;
5
6
use crate :: Error ;
6
7
7
8
pub ( crate ) struct GzipDecoder < R > ( MultiGzDecoder < R > ) ;
@@ -14,9 +15,14 @@ impl<R: io::Read> GzipDecoder<R> {
14
15
15
16
impl < R : io:: Read > io:: Read for GzipDecoder < R > {
16
17
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
17
- self . 0
18
- . read ( buf)
19
- . map_err ( |e| Error :: Decompress ( "gzip" , e) . into_io ( ) )
18
+ self . 0 . read ( buf) . map_err ( |e| {
19
+ if is_wrapped_ureq_error ( & e) {
20
+ // If this already is a ureq::Error, like Timeout, pass it along.
21
+ e
22
+ } else {
23
+ Error :: Decompress ( "gzip" , e) . into_io ( )
24
+ }
25
+ } )
20
26
}
21
27
}
22
28
Original file line number Diff line number Diff line change @@ -169,11 +169,13 @@ impl Error {
169
169
}
170
170
}
171
171
172
+ pub ( crate ) fn is_wrapped_ureq_error ( e : & io:: Error ) -> bool {
173
+ e. get_ref ( ) . map ( |x| x. is :: < Error > ( ) ) . unwrap_or ( false )
174
+ }
175
+
172
176
impl From < io:: Error > for Error {
173
177
fn from ( e : io:: Error ) -> Self {
174
- let is_wrapped_ureq_error = e. get_ref ( ) . map ( |x| x. is :: < Error > ( ) ) . unwrap_or ( false ) ;
175
-
176
- if is_wrapped_ureq_error {
178
+ if is_wrapped_ureq_error ( & e) {
177
179
// unwraps are ok, see above.
178
180
let boxed = e. into_inner ( ) . unwrap ( ) ;
179
181
let ureq = boxed. downcast :: < Error > ( ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments