better load_image errors
This commit is contained in:
parent
7d274bb3c2
commit
c2787db422
|
@ -95,6 +95,11 @@ pub fn load_image(image_base64: String) -> String {
|
|||
let mut state = STATE.lock().expect("Couldn't lock application state");
|
||||
|
||||
let image_base64: Vec<&str> = image_base64.split("base64,").collect();
|
||||
|
||||
if image_base64.len() < 2 {
|
||||
return format!("Error: Badly-formatted base64: {}", image_base64.join(""));
|
||||
}
|
||||
|
||||
let image_base64 = image_base64[1];
|
||||
|
||||
match base64::decode(image_base64) {
|
||||
|
@ -109,13 +114,13 @@ pub fn load_image(image_base64: String) -> String {
|
|||
},
|
||||
_ => {
|
||||
state.image = None;
|
||||
"Couldn't load image".to_string()
|
||||
"Error: Couldn't load image".to_string()
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
state.image = None;
|
||||
"Couldn't decode image".to_string()
|
||||
"Error: Couldn't decode image".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue