1 // Copyright (C) 2024 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use crate::wrapper::ffi; 15 16 #[derive(Clone)] 17 pub struct HttpClientError { 18 code: HttpErrorCode, 19 msg: String, 20 } 21 22 impl HttpClientError { from_ffi(inner: &ffi::HttpClientError) -> Self23 pub(crate) fn from_ffi(inner: &ffi::HttpClientError) -> Self { 24 let code = HttpErrorCode::try_from(inner.GetErrorCode()).unwrap_or_default(); 25 let msg = inner.GetErrorMessage().to_string(); 26 Self { code, msg } 27 } 28 new(code: HttpErrorCode, msg: String) -> Self29 pub fn new(code: HttpErrorCode, msg: String) -> Self { 30 Self { code, msg } 31 } 32 code(&self) -> &HttpErrorCode33 pub fn code(&self) -> &HttpErrorCode { 34 &self.code 35 } 36 msg(&self) -> &str37 pub fn msg(&self) -> &str { 38 &self.msg 39 } 40 } 41 42 #[derive(Default, Clone, PartialEq, Eq)] 43 #[repr(i32)] 44 pub enum HttpErrorCode { 45 HttpNoneErr, 46 HttpPermissionDeniedCode = 201, 47 HttpParseErrorCode = 401, 48 HttpErrorCodeBase = 2300000, 49 HttpUnsupportedProtocol, 50 HttpFailedInit, 51 HttpUrlMalformat, 52 HttpCouldntResolveProxy = 2300005, 53 HttpCouldntResolveHost, 54 HttpCouldntConnect, 55 HttpWeirdServerReply, 56 HttpRemoteAccessDenied, 57 HttpHttp2Error = 2300016, 58 HttpPartialFile = 2300018, 59 HttpWriteError = 2300023, 60 HttpUploadFailed = 2300025, 61 HttpReadError = 2300026, 62 HttpOutOfMemory, 63 HttpOperationTimedout, 64 HttpPostError = 2300034, 65 HttpTaskCanceled = 2300042, 66 HttpTooManyRedirects = 2300047, 67 HttpGotNothing = 2300052, 68 HttpSendError = 2300055, 69 HttpRecvError, 70 HttpSslCertproblem = 2300058, 71 HttpSslCipher, 72 HttpPeerFailedVerification, 73 HttpBadContentEncoding, 74 HttpFilesizeExceeded = 2300063, 75 HttpRemoteDiskFull = 2300070, 76 HttpRemoteFileExists = 2300073, 77 HttpSslCacertBadfile = 2300077, 78 HttpRemoteFileNotFound, 79 HttpSslPinnedpubkeynotmatch = 2300090, 80 HttpAuthError = 2300094, 81 #[default] 82 HttpUnknownOtherError = 2300999, 83 } 84