-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9d134e
commit d1bbf1a
Showing
8 changed files
with
348 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::api_types::{EndpointVersion, ForkVersionedResponse}; | ||
use serde::Serialize; | ||
use types::ForkName; | ||
|
||
pub const V1: EndpointVersion = EndpointVersion(1); | ||
pub const V2: EndpointVersion = EndpointVersion(2); | ||
|
||
pub fn fork_versioned_response<T: Serialize>( | ||
endpoint_version: EndpointVersion, | ||
fork_name: Option<ForkName>, | ||
data: T, | ||
) -> Result<ForkVersionedResponse<T>, warp::reject::Rejection> { | ||
let fork_name = if endpoint_version == V1 { | ||
None | ||
} else if endpoint_version == V2 { | ||
fork_name | ||
} else { | ||
return Err(unsupported_version_rejection(endpoint_version)); | ||
}; | ||
Ok(ForkVersionedResponse { | ||
version: fork_name, | ||
data, | ||
}) | ||
} | ||
|
||
pub fn unsupported_version_rejection(version: EndpointVersion) -> warp::reject::Rejection { | ||
warp_utils::reject::custom_bad_request(format!("Unsupported endpoint version: {}", version)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.