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:585–609  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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