-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User Info fetcher: Improve http request error output #509
Comments
NickLarsenNZ
changed the title
Improve http request error output
User Info fetcher: Improve http request error output
Jan 31, 2024
@fhennig, here was my Snafu that I made for util.rs #[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("failed to execute request"))]
HttpRequest { source: reqwest::Error },
#[snafu(display("failed to parse json response"))]
ParseJson { source: reqwest::Error },
#[snafu(display("response was an http error"))]
HttpErrorResponse { source: reqwest::Error },
#[snafu(display("response was an http error: {text}"))]
Something { text: String },
} That last one was the one most relevant to this issue. The rest would be necessary to return Snafu's regardless of this issue being solved.) ❌ A failed attemptI got this far before realising it won't work, and we should just use do pub async fn send_json_request3<T: DeserializeOwned>(req: RequestBuilder) -> Result<T> {
let response = req.send().await.context(HttpRequestSnafu)?;
match response.error_for_status() {
Ok(response) => {
let json = response.json().await.context(ParseJsonSnafu)?;
Ok(json)
}
Err(error) => {
let text = response
.text() // try bytes
.await
.unwrap_or("unable to decode response body as text".to_owned());
Err(Error::Something { text })
// Err(Error::Something {
// text: "blah".to_owned(),
// })
}
}
} |
fhennig
moved this from Refinement: In Progress
to Development: In Progress
in Stackable Engineering
Jan 31, 2024
fhennig
moved this from Development: In Progress
to Development: Waiting for Review
in Stackable Engineering
Feb 1, 2024
NickLarsenNZ
moved this from Development: Waiting for Review
to Development: In Review
in Stackable Engineering
Feb 1, 2024
fhennig
moved this from Development: In Review
to Development: Done
in Stackable Engineering
Feb 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
Currently, we raise an error if the response to an HTTP request is 4xx or 5xx. We only know which part of the code the User Info Fetcher failed on. We have no HTTP response body in the error to give a hint to the problem. Eg: Is it a WAF or proxy issue, or are we reaching the idP but some configuration is wrong?
opa-operator/rust/user-info-fetcher/src/backend/keycloak.rs
Lines 11 to 14 in a4a6f44
The difficulty in adding the extra indfoamtion is that the Reqwest library consumes the response when calling methods like
.text()
(or.json()
), orerror_for_status()
, and we need a combination of both methods.Suggested fix
Don't make use of
error_for_status()
(which simply checks for 4xx or 5xx errors) and instead manually check the status code, and then either response with thejson()
, or produce a Snafu error containing thetext()
(which is fallible, so consideration should be made how to handle that).Acceptance criteria
util::send_json_request
The text was updated successfully, but these errors were encountered: