better load_image errors

This commit is contained in:
Max Bradbury 2020-11-08 17:34:48 +00:00
parent 7d274bb3c2
commit c2787db422
1 changed files with 7 additions and 2 deletions

View File

@ -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()
}
}
}