-
Notifications
You must be signed in to change notification settings - Fork 34
[PM-36839] Prepare API base Error #1049
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
Merged
+146
β49
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
708c16b
[PM-36839] Prepare API base Error
dani-garcia 6ba8fa6
Merge branch 'main' into ps/PM-36839-prepare-api-base-error
dani-garcia da585b3
use actual statuscode type and implement uniffi/serialize support
dani-garcia a2a04ba
Add dep
dani-garcia 41be750
Merge branch 'main' into ps/PM-36839-prepare-api-base-error
dani-garcia 547fc7b
Implement our own serialization, no need for a crate
dani-garcia 62ddb7b
Fix renovate conf
dani-garcia c20145a
Merge branch 'main' into ps/PM-36839-prepare-api-base-error
dani-garcia 6961015
Merge branch 'main' into ps/PM-36839-prepare-api-base-error
dani-garcia 07feb0f
Merge branch 'main' into ps/PM-36839-prepare-api-base-error
dani-garcia 0249a2f
Merge branch 'main' into ps/PM-36839-prepare-api-base-error
dani-garcia c63c0c6
Fix merge conflict
dani-garcia 0d1055f
Merge branch 'main' into ps/PM-36839-prepare-api-base-error
dani-garcia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
| //! Serde helpers for [`http::StatusCode`], used via `#[serde(with = ...)]`. | ||
|
|
||
| use http::StatusCode; | ||
| use serde::{Deserialize, Deserializer, Serializer, de::Error}; | ||
|
|
||
| pub fn serialize<S: Serializer>(status: &StatusCode, ser: S) -> Result<S::Ok, S::Error> { | ||
| ser.serialize_u16(status.as_u16()) | ||
| } | ||
|
|
||
| pub fn deserialize<'de, D: Deserializer<'de>>(de: D) -> Result<StatusCode, D::Error> { | ||
| let value = u16::deserialize(de)?; | ||
| StatusCode::from_u16(value).map_err(D::Error::custom) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use http::StatusCode; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, PartialEq)] | ||
| struct Wrapper { | ||
| #[serde(with = "super")] | ||
| status: StatusCode, | ||
| } | ||
|
|
||
| #[test] | ||
| fn serializes_as_u16() { | ||
| let json = serde_json::to_string(&Wrapper { | ||
| status: StatusCode::NOT_FOUND, | ||
| }) | ||
| .unwrap(); | ||
| assert_eq!(json, r#"{"status":404}"#); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserializes_from_u16() { | ||
| let wrapper: Wrapper = serde_json::from_str(r#"{"status":201}"#).unwrap(); | ||
| assert_eq!(wrapper.status, StatusCode::CREATED); | ||
| } | ||
|
|
||
| #[test] | ||
| fn rejects_invalid_status() { | ||
| let err = serde_json::from_str::<Wrapper>(r#"{"status":99}"#).unwrap_err(); | ||
| assert!(err.to_string().contains("invalid status code")); | ||
| } | ||
| } |
This file contains hidden or 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,10 @@ | ||
| //! Custom Uniffi type converters for types defined by external crates. | ||
|
|
||
| use bitwarden_uniffi_error::convert_result; | ||
| use reqwest::StatusCode; | ||
|
|
||
| uniffi::custom_type!(StatusCode, u16, { | ||
| remote, | ||
| try_lift: |val| convert_result(StatusCode::from_u16(val)), | ||
| lower: |obj| obj.as_u16(), | ||
| }); |
This file contains hidden or 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,9 @@ | ||
| [bindings.kotlin] | ||
| package_name = "com.bitwarden.api.base" | ||
| generate_immutable_records = true | ||
| android = true | ||
|
|
||
| [bindings.swift] | ||
| ffi_module_name = "BitwardenApiBaseFFI" | ||
| module_name = "BitwardenApiBase" | ||
| generate_immutable_records = true |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.