Skip to main content

parse_subscribe_error

Function parse_subscribe_error 

Source
pub fn parse_subscribe_error(text: &str) -> Option<String>
Expand description

Detect BCS market-data subscribe error payloads (errors array).

Returns the message of the first error, or a default text when it has none. None when the text is not JSON or has no non-empty errors array.

§Examples

use brokapi_bcs::map::market::parse_subscribe_error;

let text = r#"{"errors":[{"message":"unknown instrument"}]}"#;
assert_eq!(parse_subscribe_error(text).as_deref(), Some("unknown instrument"));
assert_eq!(parse_subscribe_error(r#"{"data":[]}"#), None);