use suppaftp::FtpError;
use suppaftp::Status;
use opendal_core::Error;
use opendal_core::ErrorKind;
pub(super) fn format_ftp_error(err: FtpError) -> Error {
let (kind, retryable) = match err {
FtpError::UnexpectedResponse(ref resp) if resp.status == Status::NotAvailable => {
(ErrorKind::Unexpected, true)
}
FtpError::UnexpectedResponse(ref resp) if resp.status == Status::FileUnavailable => {
(ErrorKind::NotFound, false)
}
FtpError::BadResponse => (ErrorKind::Unexpected, true),
_ => (ErrorKind::Unexpected, false),
};
let mut err = Error::new(kind, "ftp error").set_source(err);
if retryable {
err = err.set_temporary();
}
err
}