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

Allow inspection of ErrorExtensions for testing #855

Closed
Follpvosten opened this issue Mar 3, 2022 · 2 comments
Closed

Allow inspection of ErrorExtensions for testing #855

Follpvosten opened this issue Mar 3, 2022 · 2 comments
Labels
enhancement New feature or request Stale

Comments

@Follpvosten
Copy link
Contributor

Description of the feature

ErrorExtensionValues is current write-only, as it doesn't implement Deref, the wrapped BTreeMap is private and it doesn't expose any method to get an existing extension.

This means to check for an expected extension, I have to convert it to a serde value first, for example:

let extensions = serde_json::to_value(error.extensions.unwrap()).unwrap();
let extensions = extensions.as_object().unwrap();
assert_eq!(extensions.get("code"), Some(&401.into()));

I'd suggest either implementing Deref<Target = BTreeMap<String, Value>> on ErrorExtensionValues, or alternatively just exposing a get(&self, key: &impl Borrow<String> + Ord) -> Option<&Value> method. This would make it much easier to check if a specific value has been set to an extension, without going through serde.

let extensions = error.extensions.unwrap();
assert_eq!(extensions.get("code"), Some(&401.into());

If you want to keep the extensions write-only for non-test code by default, you could feature-flag this impl or method.

@Follpvosten Follpvosten added the enhancement New feature or request label Mar 3, 2022
sunli829 added a commit that referenced this issue Mar 14, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Aug 31, 2022
@github-actions
Copy link

github-actions bot commented Sep 6, 2022

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as completed Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Stale
Projects
None yet
Development

No branches or pull requests

1 participant