pyerror: convert more eden api errors to HttpError

Summary: I'm expanding HttpError to mean something like "we had a problem when making an http request". It isn't used very much in Python, and I'm co-opting it to be one of the key triggers for running the network doctor automatically.

Reviewed By: DurhamG

Differential Revision: D34739986

fbshipit-source-id: daea571b06bf030257c6acf534af45abbbf2048c
This commit is contained in:
Muir Manders 2022-03-17 11:11:53 -07:00 committed by Facebook GitHub Bot
parent 7d811e26dc
commit 7d1b784ae1
2 changed files with 13 additions and 12 deletions

View File

@ -111,8 +111,8 @@ Inspect results
Test move bookmark failure (invalid from)
$ hgedenapi debugapi -e setbookmark -i "'master_bookmark'" -i "'$D'" -i "'$C'" 2>&1 | grep 'error.RustError'
error.RustError: expected response, but none returned by the server
$ hgedenapi debugapi -e setbookmark -i "'master_bookmark'" -i "'$D'" -i "'$C'" 2>&1 | grep 'error.HttpError'
error.HttpError: expected response, but none returned by the server
Inspect results
$ hgedenapi pull -q
@ -130,8 +130,8 @@ Inspect results
Test delete bookmark failure (invalid from)
$ hgedenapi debugapi -e setbookmark -i "'create_bookmark'" -i "None" -i "'$D'" 2>&1 | grep 'error.RustError'
error.RustError: expected response, but none returned by the server
$ hgedenapi debugapi -e setbookmark -i "'create_bookmark'" -i "None" -i "'$D'" 2>&1 | grep 'error.HttpError'
error.HttpError: expected response, but none returned by the server
Inspect results
$ hgedenapi pull -q
@ -149,8 +149,8 @@ Inspect results
Test create bookmark failure (already exists)
$ hgedenapi debugapi -e setbookmark -i "'create_bookmark'" -i "'$D'" -i "None" 2>&1 | grep 'error.RustError'
error.RustError: expected response, but none returned by the server
$ hgedenapi debugapi -e setbookmark -i "'create_bookmark'" -i "'$D'" -i "None" 2>&1 | grep 'error.HttpError'
error.HttpError: expected response, but none returned by the server
Inspect results
$ hgedenapi pull -q

View File

@ -140,13 +140,14 @@ fn register_error_handlers() {
py,
cpython_ext::Str::from(format!("{:?}", e)),
))
} else if let Some(edenapi::EdenApiError::Http(e)) =
e.downcast_ref::<edenapi::EdenApiError>()
{
} else if let Some(e) = e.downcast_ref::<edenapi::EdenApiError>() {
match e {
http_client::HttpClientError::Tls(http_client::TlsError { source: e, .. }) => Some(
PyErr::new::<TlsError, _>(py, cpython_ext::Str::from(e.to_string())),
),
edenapi::EdenApiError::Http(http_client::HttpClientError::Tls(
http_client::TlsError { source: e, .. },
)) => Some(PyErr::new::<TlsError, _>(
py,
cpython_ext::Str::from(e.to_string()),
)),
_ => Some(PyErr::new::<HttpError, _>(
py,
cpython_ext::Str::from(e.to_string()),