api-client: Handle body_offset is None

Handle the case `body_offset` is `None` instead of calling `unwrap()`
which leads to a panic.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
This commit is contained in:
Maximilian Nitsch 2022-07-26 14:10:36 +02:00 committed by Sebastien Boeuf
parent c46a9592c0
commit 87c0791d53

View File

@ -131,7 +131,7 @@ fn parse_http_response(socket: &mut dyn Read) -> Result<Option<String>, Error> {
}
}
}
let body_string = content_length.and(Some(String::from(&res[body_offset.unwrap()..])));
let body_string = content_length.and(body_offset.map(|o| String::from(&res[o..])));
let status_code = get_status_code(&res)?;
if status_code.is_server_error() {