mirror of
https://github.com/facebook/sapling.git
synced 2025-01-01 09:37:56 +03:00
edenapi: check HTTP status code
Summary: Previously, `edenapi` would unconditionally attempt to parse the response body as CBOR, resulting in cryptic error messages if the server had returned an error instead of the expected content. Instead, we should first check that the request was successful, and only then attempt to parse the body. Reviewed By: quark-zju Differential Revision: D15426868 fbshipit-source-id: ceaf0d6691b509bcd934d6b99ceefb3e83e798ca
This commit is contained in:
parent
bb67907b7b
commit
14bf3a15b0
@ -247,8 +247,19 @@ impl EdenApiCurlClient {
|
||||
let start = Instant::now();
|
||||
|
||||
driver.perform(|res| {
|
||||
let easy = res?;
|
||||
let mut easy = res?;
|
||||
let code = easy.response_code()?;
|
||||
let data = easy.get_ref().data();
|
||||
|
||||
if code >= 400 {
|
||||
let msg = String::from_utf8_lossy(data);
|
||||
bail!(
|
||||
"Received HTTP status code {} with response: {:?}",
|
||||
code,
|
||||
msg
|
||||
);
|
||||
}
|
||||
|
||||
let response = serde_cbor::from_slice::<T>(data)?;
|
||||
response_cb(response)
|
||||
})?;
|
||||
|
Loading…
Reference in New Issue
Block a user