MCPcopy Create free account
hub / github.com/cowprotocol/services / rich_errors_handle_serialization_errors

Function rich_errors_handle_serialization_errors

crates/orderbook/src/api.rs:586–610  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

584
585 #[tokio::test]
586 async fn rich_errors_handle_serialization_errors() {
587 struct AlwaysErrors;
588 impl Serialize for AlwaysErrors {
589 fn serialize<S>(&self, _: S) -> Result<S::Ok, S::Error>
590 where
591 S: serde::Serializer,
592 {
593 Err(ser::Error::custom("error"))
594 }
595 }
596
597 let response = rich_error("foo", "bar", AlwaysErrors).into_response();
598 // SAFETY: usize::MAX is ok here because it's a test
599 let bytes = axum::body::to_bytes(response.into_body(), usize::MAX)
600 .await
601 .unwrap();
602
603 assert_eq!(
604 serde_json::from_slice::<serde_json::Value>(&bytes).unwrap(),
605 json!({
606 "errorType": "foo",
607 "description": "bar",
608 })
609 );
610 }
611
612 #[tokio::test]
613 async fn maps_known_solver_errors_to_bad_request_responses() {

Callers

nothing calls this directly

Calls 3

rich_errorFunction · 0.85
unwrapMethod · 0.80
into_responseMethod · 0.45

Tested by

no test coverage detected