You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
I'd suggest either implementing
Deref<Target = BTreeMap<String, Value>>
on ErrorExtensionValues, or alternatively just exposing aget(&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.If you want to keep the extensions write-only for non-test code by default, you could feature-flag this impl or method.
The text was updated successfully, but these errors were encountered: