-
Notifications
You must be signed in to change notification settings - Fork 298
Cosmos: Fix #2824 by forcing 'enable_content_response_on_write' on for read item #2894
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
base: main
Are you sure you want to change the base?
Changes from all commits
027abb3
98c57fb
fa81d1b
6fb7837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,13 @@ mod signature_target; | |
use std::sync::Arc; | ||
|
||
pub use authorization_policy::AuthorizationPolicy; | ||
use azure_core::http::{ | ||
request::{options::ContentType, Request}, | ||
response::Response, | ||
ClientOptions, Context, Method, PagerState, RawResponse, | ||
use azure_core::{ | ||
error::HttpError, | ||
http::{ | ||
request::{options::ContentType, Request}, | ||
response::Response, | ||
ClientOptions, Context, Method, PagerState, RawResponse, | ||
}, | ||
}; | ||
use futures::TryStreamExt; | ||
use serde::de::DeserializeOwned; | ||
|
@@ -64,7 +67,7 @@ impl CosmosPipeline { | |
resource_link: ResourceLink, | ||
) -> azure_core::Result<RawResponse> { | ||
let ctx = ctx.with_value(resource_link); | ||
self.pipeline.send(&ctx, request).await | ||
self.pipeline.send(&ctx, request).await?.success().await | ||
} | ||
|
||
pub async fn send<T>( | ||
|
@@ -75,7 +78,7 @@ impl CosmosPipeline { | |
) -> azure_core::Result<Response<T>> { | ||
self.send_raw(ctx, request, resource_link) | ||
.await | ||
.map(|r| r.into()) | ||
.map(Into::into) | ||
} | ||
|
||
pub fn send_query_request<T: DeserializeOwned + Send>( | ||
|
@@ -105,7 +108,7 @@ impl CosmosPipeline { | |
req.insert_header(constants::CONTINUATION, continuation); | ||
} | ||
|
||
let resp = pipeline.send(&ctx, &mut req).await?; | ||
let resp = pipeline.send(&ctx, &mut req).await?.success().await?; | ||
let page = FeedPage::<T>::from_response(resp).await?; | ||
|
||
Ok(page.into()) | ||
|
@@ -191,3 +194,39 @@ pub(crate) fn create_base_query_request(url: Url, query: &Query) -> azure_core:: | |
request.set_json(query)?; | ||
Ok(request) | ||
} | ||
|
||
trait ResponseExt { | ||
async fn success(self) -> azure_core::Result<Self> | ||
where | ||
Self: Sized; | ||
} | ||
|
||
impl<T, F> ResponseExt for Response<T, F> { | ||
async fn success(self) -> azure_core::Result<Self> { | ||
if self.status().is_success() { | ||
Ok(self) | ||
} else { | ||
RawResponse::from(self).success().await.map(Into::into) | ||
analogrelay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
impl ResponseExt for RawResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chlowell this is a good idea we might consider in |
||
async fn success(self) -> azure_core::Result<Self> { | ||
if self.status().is_success() { | ||
Ok(self) | ||
} else { | ||
let http_error = HttpError::new(self).await; | ||
let status = http_error.status(); | ||
let error_kind = azure_core::error::ErrorKind::http_response( | ||
status, | ||
http_error.error_code().map(ToOwned::to_owned), | ||
); | ||
Err(azure_core::Error::full( | ||
error_kind, | ||
http_error, | ||
format!("Request failed with status code: {}", status), | ||
)) | ||
} | ||
} | ||
} | ||
heaths marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.