[−][src]Function superkeyloader_lib::error_handler_wrapper
pub fn error_handler_wrapper(
res: Result<Vec<String>, u16>
) -> Result<Vec<String>, String>
Handle HTTP status codes errors and "no SSH keys" error.
TODO: Add context about username and service to improve error messages
Errors
The function use the crate exitfailure
to print a better error message on exit.
It returns an error string that contains the error description on:
- Input vector length is 0
- Input has no
Ok
result, but has error code:404
HTTP Status Code -> Usually it means that the user doesn't exists1001
Internal error -> GitHub username is invalid (see https://github.com/shinnn/github-username-regex)1002
Internal error -> GitHub API response could not be parsed- Every other status code -> Unrecognized HTTP status code (i.e. 500, 501, etc.)
Assuming that a 2XX response will always have an
Ok
value, so it will never reach 'error matching'
Examples
No errors
use superkeyloader_lib::error_handler_wrapper; let data = vec!("key1".to_string(), "key1".to_string()); let input = Ok(data.clone()); let output = error_handler_wrapper(input); assert_eq!(data, output.unwrap());
Missing user (404 status code)
use superkeyloader_lib::error_handler_wrapper; let error_code: u16 = 404; let input = Err(error_code); let output = error_handler_wrapper(input); assert!(output.is_err()); let expected_output = String::from("Wrong username"); let error_message = output.err().unwrap(); assert!(error_message.contains(&expected_output));