opendal/services/ghac/
error.rs1use http::Response;
19use http::StatusCode;
20
21use crate::raw::*;
22use crate::*;
23
24pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
26 let (parts, body) = resp.into_parts();
27
28 let (kind, retryable) = match parts.status {
29 StatusCode::NOT_FOUND | StatusCode::NO_CONTENT => (ErrorKind::NotFound, false),
30 StatusCode::CONFLICT => (ErrorKind::AlreadyExists, false),
31 StatusCode::FORBIDDEN => (ErrorKind::PermissionDenied, false),
32 StatusCode::TOO_MANY_REQUESTS => (ErrorKind::RateLimited, true),
33 StatusCode::INTERNAL_SERVER_ERROR
34 | StatusCode::BAD_GATEWAY
35 | StatusCode::SERVICE_UNAVAILABLE
36 | StatusCode::GATEWAY_TIMEOUT => (ErrorKind::Unexpected, true),
37 _ => (ErrorKind::Unexpected, false),
38 };
39
40 let bs = body.to_bytes();
41 let message = String::from_utf8_lossy(&bs);
42
43 let mut err = Error::new(kind, message);
44
45 err = with_error_response_context(err, parts);
46
47 if retryable {
48 err = err.set_temporary();
49 }
50
51 err
52}