Skip to content
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

refactor: refactor all body.copy_to_bytes(body.remaining()) #5561

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/services/aliyun_drive/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ struct AliyunDriveError {
}

pub(super) fn parse_error(res: Response<Buffer>) -> Error {
let (parts, mut body) = res.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = res.into_parts();
let bs = body.to_bytes();
let (code, message) = serde_json::from_reader::<_, AliyunDriveError>(bs.clone().reader())
.map(|err| (Some(err.code), err.message))
.unwrap_or((None, String::from_utf8_lossy(&bs).into_owned()));
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/alluxio/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ struct AlluxioError {
}

pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let mut kind = match parts.status.as_u16() {
500 => ErrorKind::Unexpected,
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/azdls/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ impl Debug for AzdlsError {

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/azfile/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ impl Debug for AzfileError {

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/b2/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ struct B2Error {

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (mut kind, mut retryable) = match parts.status.as_u16() {
403 => (ErrorKind::PermissionDenied, false),
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/chainsafe/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct ChainsafeSubError {

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status.as_u16() {
401 | 403 => (ErrorKind::PermissionDenied, false),
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/cloudflare_kv/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use crate::*;

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (mut kind, mut retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/cos/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct CosError {

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/d1/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use std::fmt::Debug;
use std::fmt::Formatter;

use bytes::Buf;
use http::header;
use http::Request;
use http::StatusCode;
Expand Down Expand Up @@ -287,8 +286,8 @@ impl kv::Adapter for Adapter {
let status = resp.status();
match status {
StatusCode::OK | StatusCode::PARTIAL_CONTENT => {
let mut body = resp.into_body();
let bs = body.copy_to_bytes(body.remaining());
let body = resp.into_body();
let bs = body.to_bytes();
let d1_response = D1Response::parse(&bs)?;
Ok(d1_response.get_result(&self.value_field))
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/d1/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use crate::*;

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (mut kind, mut retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/dbfs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use std::fmt::Debug;

use bytes::Buf;
use http::Response;
use http::StatusCode;
use serde::Deserialize;
Expand All @@ -44,8 +43,8 @@ impl Debug for DbfsError {
}

pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/dropbox/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use bytes::Buf;
use http::Response;
use http::StatusCode;
use serde::Deserialize;
Expand All @@ -31,8 +30,8 @@ pub struct DropboxErrorResponse {

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (mut kind, mut retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/gdrive/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use bytes::Buf;
use http::Response;
use http::StatusCode;
use serde::Deserialize;
Expand All @@ -35,8 +34,8 @@ struct GdriveInnerError {

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (mut kind, mut retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/ghac/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use bytes::Buf;
use http::Response;
use http::StatusCode;

Expand All @@ -24,7 +23,7 @@ use crate::*;

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let (parts, body) = resp.into_parts();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND | StatusCode::NO_CONTENT => (ErrorKind::NotFound, false),
Expand All @@ -38,7 +37,7 @@ pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
_ => (ErrorKind::Unexpected, false),
};

let bs = body.copy_to_bytes(body.remaining());
let bs = body.to_bytes();
let message = String::from_utf8_lossy(&bs);

let mut err = Error::new(kind, message);
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/github/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct GithubSubError {

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status.as_u16() {
401 | 403 => (ErrorKind::PermissionDenied, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/http/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use bytes::Buf;
use http::Response;
use http::StatusCode;

Expand All @@ -24,8 +23,8 @@ use crate::*;

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/huggingface/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use std::fmt::Debug;

use bytes::Buf;
use http::Response;
use http::StatusCode;
use serde::Deserialize;
Expand All @@ -41,8 +40,8 @@ impl Debug for HuggingfaceError {
}

pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/icloud/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ impl PathQuery for IcloudPathQuery {
}

pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let mut kind = match parts.status.as_u16() {
421 | 450 | 500 => ErrorKind::NotFound,
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/ipfs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use bytes::Buf;
use http::Response;
use http::StatusCode;

Expand All @@ -24,8 +23,8 @@ use crate::*;

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/ipmfs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use bytes::Buf;
use http::Response;
use http::StatusCode;
use serde::Deserialize;
Expand Down Expand Up @@ -45,8 +44,8 @@ struct IpfsError {
///
/// ref: https://docs.ipfs.tech/reference/kubo/rpc/#http-status-codes
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let ipfs_error = de::from_slice::<IpfsError>(&bs).ok();

Expand Down
5 changes: 2 additions & 3 deletions core/src/services/koofr/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
// specific language governing permissions and limitations
// under the License.

use bytes::Buf;
use http::Response;

use crate::raw::*;
use crate::*;

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status.as_u16() {
403 => (ErrorKind::PermissionDenied, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/lakefs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use std::fmt::Debug;

use bytes::Buf;
use http::Response;
use http::StatusCode;
use serde::Deserialize;
Expand All @@ -41,8 +40,8 @@ impl Debug for LakefsError {
}

pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/libsql/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use bytes::Buf;
use http::Response;
use http::StatusCode;

Expand All @@ -24,8 +23,8 @@ use crate::*;

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/obs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct ObsError {

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
5 changes: 2 additions & 3 deletions core/src/services/onedrive/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use bytes::Buf;
use http::Response;
use http::StatusCode;

Expand All @@ -24,8 +23,8 @@ use crate::*;

/// Parse error response into Error.
pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (parts, mut body) = resp.into_parts();
let bs = body.copy_to_bytes(body.remaining());
let (parts, body) = resp.into_parts();
let bs = body.to_bytes();

let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/onedrive/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl OneDriveWriter {
}

async fn create_upload_session(&self) -> Result<OneDriveUploadSessionCreationResponseBody> {
let file_name_from_path = self.path.split('/').last().ok_or_else(|| {
let file_name_from_path = self.path.split('/').next_back().ok_or_else(|| {
Error::new(
ErrorKind::Unexpected,
"connection string must have AccountName",
Expand Down
Loading
Loading