Skip to content

add Method & StatusCode to azure_core #849

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion sdk/core/src/method.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::ops::Deref;
use crate::error::{Error, ErrorKind};
use std::{ops::Deref, str::FromStr};

#[derive(PartialEq, Eq, Clone, Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not Copy?

pub struct Method(pub(crate) http_types::Method);
Expand Down Expand Up @@ -34,3 +35,12 @@ impl Default for Method {
Method::GET
}
}

impl FromStr for Method {
type Err = Error;
fn from_str(s: &str) -> crate::Result<Self> {
Ok(Method(http_types::Method::from_str(s).map_err(
|error| Error::full(ErrorKind::DataConversion, error, "Method::from_str failed"),
)?))
}
}
2 changes: 1 addition & 1 deletion sdk/core/src/mock/mock_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl MockResponse {
)?;

let response = Response::new(
status_code,
status_code.clone(),
header_map.clone(),
Box::pin(BytesStream::new(response_bytes.clone())),
);
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/src/mock/player_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Policy for MockTransportPlayerPolicy {
if expected_request.method() != request.method() {
return Err(Error::with_message(ErrorKind::MockFramework, || {
format!(
"mismatched HTTP request method. Actual: {0}, Expected: {1}",
"mismatched HTTP request method. Actual: {0:?}, Expected: {1:?}",
expected_request.method(),
request.method(),
)
Expand Down
12 changes: 6 additions & 6 deletions sdk/core/src/status_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ impl StatusCode {
))
}

pub const REQUEST_TIMEOUT: StatusCode = StatusCode(http_types::StatusCode::RequestTimeout);
pub const TOO_MANY_REQUESTS: StatusCode = StatusCode(http_types::StatusCode::TooManyRequests);
pub const BAD_GATEWAY: StatusCode = StatusCode(http_types::StatusCode::BadGateway);
pub const GATEWAY_TIMEOUT: StatusCode = StatusCode(http_types::StatusCode::GatewayTimeout);
pub const INTERNAL_SERVER_ERROR: StatusCode =
StatusCode(http_types::StatusCode::InternalServerError);
pub const BAD_GATEWAY: StatusCode = StatusCode(http_types::StatusCode::BadGateway);
pub const NOT_MODIFIED: StatusCode = StatusCode(http_types::StatusCode::NotModified);
pub const OK: StatusCode = StatusCode(http_types::StatusCode::Ok);
pub const REQUEST_TIMEOUT: StatusCode = StatusCode(http_types::StatusCode::RequestTimeout);
pub const SERVICE_UNAVAILABLE: StatusCode =
StatusCode(http_types::StatusCode::ServiceUnavailable);
pub const GATEWAY_TIMEOUT: StatusCode = StatusCode(http_types::StatusCode::GatewayTimeout);
pub const OK: StatusCode = StatusCode(http_types::StatusCode::Ok);
pub const NOT_MODIFIED: StatusCode = StatusCode(http_types::StatusCode::NotModified);
pub const TOO_MANY_REQUESTS: StatusCode = StatusCode(http_types::StatusCode::TooManyRequests);
}

impl Default for StatusCode {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I like this impl. OK does not logically feel like the "default" status code to me.

Expand Down