Return Err on deadline checked_add overflow instead of panic (#517)
This commit is contained in:
@@ -3,12 +3,13 @@ use std::{fmt, time};
|
||||
|
||||
use url::{form_urlencoded, ParseError, Url};
|
||||
|
||||
use crate::agent::Agent;
|
||||
use crate::body::Payload;
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::header::{self, Header};
|
||||
use crate::middleware::MiddlewareNext;
|
||||
use crate::unit::{self, Unit};
|
||||
use crate::Response;
|
||||
use crate::{agent::Agent, error::Error};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
@@ -123,7 +124,15 @@ impl Request {
|
||||
None => None,
|
||||
Some(timeout) => {
|
||||
let now = time::Instant::now();
|
||||
Some(now.checked_add(timeout).unwrap())
|
||||
match now.checked_add(timeout) {
|
||||
Some(dl) => Some(dl),
|
||||
None => {
|
||||
return Err(Error::new(
|
||||
ErrorKind::Io,
|
||||
Some("Request deadline overflowed".to_string()),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user