|
1 | | -use anyhow::Context; |
2 | 1 | use serde::Deserialize; |
3 | 2 |
|
4 | 3 | use shopify_function::prelude::*; |
@@ -27,35 +26,37 @@ type CartResponseData = cart_run::input::ResponseData; |
27 | 26 | type DeliveryResponseData = delivery_run::input::ResponseData; |
28 | 27 |
|
29 | 28 | impl CartResponseData { |
30 | | - fn metafield(&self) -> anyhow::Result<Metafield> { |
| 29 | + fn metafield(&self) -> Result<Metafield> { |
31 | 30 | let metafield = self |
32 | 31 | .discount_node |
33 | 32 | .metafield |
34 | 33 | .as_ref() |
35 | | - .context("Missing metafield")?; |
36 | | - serde_json::from_str(&metafield.value).context("Metafield value cannot be parsed") |
| 34 | + .ok_or("Missing metafield")?; |
| 35 | + serde_json::from_str(&metafield.value) |
| 36 | + .map_err(|_| "Metafield value cannot be parsed".into()) |
37 | 37 | } |
38 | | - fn valid_discount_codes(&self) -> anyhow::Result<Vec<String>> { |
39 | | - let fetch_result = self.fetch_result.as_ref().context("Missing fetch result")?; |
40 | | - let body = fetch_result.body.as_ref().context("Missing body")?; |
41 | | - serde_json::from_str(body).context("Fetch result body cannot be parsed") |
| 38 | + fn valid_discount_codes(&self) -> Result<Vec<String>> { |
| 39 | + let fetch_result = self.fetch_result.as_ref().ok_or("Missing fetch result")?; |
| 40 | + let body = fetch_result.body.as_ref().ok_or("Missing body")?; |
| 41 | + serde_json::from_str(body).map_err(|_| "Fetch result body cannot be parsed".into()) |
42 | 42 | } |
43 | 43 | } |
44 | 44 |
|
45 | 45 | impl DeliveryResponseData { |
46 | | - fn metafield(&self) -> anyhow::Result<Metafield> { |
47 | | - let metafield = &self |
| 46 | + fn metafield(&self) -> Result<Metafield> { |
| 47 | + let metafield = self |
48 | 48 | .discount_node |
49 | 49 | .metafield |
50 | 50 | .as_ref() |
51 | | - .context("Missing metafield")?; |
52 | | - serde_json::from_str(&metafield.value).context("Metafield value cannot be parsed") |
| 51 | + .ok_or("Missing metafield")?; |
| 52 | + serde_json::from_str(&metafield.value) |
| 53 | + .map_err(|_| "Metafield value cannot be parsed".into()) |
53 | 54 | } |
54 | 55 |
|
55 | | - fn valid_discount_codes(&self) -> anyhow::Result<Vec<String>> { |
56 | | - let fetch_result = self.fetch_result.as_ref().expect("Missing fetch result"); |
57 | | - let body = fetch_result.body.as_ref().expect("Missing body"); |
58 | | - serde_json::from_str(body).context("Fetch result body cannot be parsed") |
| 56 | + fn valid_discount_codes(&self) -> Result<Vec<String>> { |
| 57 | + let fetch_result = self.fetch_result.as_ref().ok_or("Missing fetch result")?; |
| 58 | + let body = fetch_result.body.as_ref().ok_or("Missing body")?; |
| 59 | + serde_json::from_str(body).map_err(|_| "Fetch result body cannot be parsed".into()) |
59 | 60 | } |
60 | 61 | } |
61 | 62 |
|
|
0 commit comments