Created
July 15, 2019 13:59
-
-
Save andreastt/784c84ca6c9732aaa573bdcd040671de to your computer and use it in GitHub Desktop.
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
diff --git a/src/message.rs b/src/message.rs | |
index b11b66d..72f0215 100644 | |
--- a/src/message.rs | |
+++ b/src/message.rs | |
@@ -1,10 +1,10 @@ | |
-use serde::de::{self, SeqAccess, Visitor}; | |
+use serde::de::{self, SeqAccess, Unexpected, Visitor}; | |
use serde::{Deserialize, Deserializer, Serialize, Serializer}; | |
use serde_json::{Map, Value}; | |
use serde_repr::{Deserialize_repr, Serialize_repr}; | |
use std::fmt; | |
-use crate::error::MarionetteError; | |
+use crate::error::{Error, MarionetteError}; | |
use crate::marionette; | |
use crate::webdriver; | |
@@ -160,22 +160,24 @@ impl<'de> Visitor<'de> for MessageVisitor { | |
} | |
MessageDirection::Outgoing => { | |
- let maybe_error: Value = seq | |
+ let maybe_error: Option<MarionetteError> = seq | |
.next_element()? | |
.ok_or_else(|| de::Error::invalid_length(2, &self))?; | |
- let response = if let Value::Null = maybe_error { | |
- //Error is null | |
+ let response = if let Some(error) = maybe_error { | |
+ let _ = seq | |
+ .next_element::<Value>()? | |
+ .ok_or_else(|| de::Error::invalid_length(3, &self))? | |
+ .as_null() | |
+ .ok_or_else(|| de::Error::invalid_type(Unexpected::Unit, &self))?; | |
+ Response::Error { id, error } | |
+ } else { | |
let result: Payload = seq | |
.next_element()? | |
.ok_or_else(|| de::Error::invalid_length(3, &self))?; | |
Response::Result { id, result } | |
- } else { | |
- println!("{:?}", maybe_error); | |
- let error = serde_json::from_value::<MarionetteError>(maybe_error) | |
- .map_err(de::Error::custom)?; | |
- Response::Error { id, error } | |
}; | |
+ | |
Message::Outgoing(response) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment