00001 #include "cpr/error.h" 00002 00003 #include <curl/curl.h> 00004 00005 namespace cpr { 00006 00007 ErrorCode Error::getErrorCodeForCurlError(std::int32_t curl_code) { 00008 switch (curl_code) { 00009 case CURLE_OK: 00010 return ErrorCode::OK; 00011 case CURLE_UNSUPPORTED_PROTOCOL: 00012 return ErrorCode::UNSUPPORTED_PROTOCOL; 00013 case CURLE_URL_MALFORMAT: 00014 return ErrorCode::INVALID_URL_FORMAT; 00015 case CURLE_COULDNT_RESOLVE_PROXY: 00016 return ErrorCode::PROXY_RESOLUTION_FAILURE; 00017 case CURLE_COULDNT_RESOLVE_HOST: 00018 return ErrorCode::HOST_RESOLUTION_FAILURE; 00019 case CURLE_COULDNT_CONNECT: 00020 return ErrorCode::CONNECTION_FAILURE; 00021 case CURLE_OPERATION_TIMEDOUT: 00022 return ErrorCode::OPERATION_TIMEDOUT; 00023 case CURLE_SSL_CONNECT_ERROR: 00024 return ErrorCode::SSL_CONNECT_ERROR; 00025 case CURLE_PEER_FAILED_VERIFICATION: 00026 return ErrorCode::SSL_REMOTE_CERTIFICATE_ERROR; 00027 case CURLE_GOT_NOTHING: 00028 return ErrorCode::EMPTY_RESPONSE; 00029 case CURLE_SSL_ENGINE_NOTFOUND: 00030 return ErrorCode::GENERIC_SSL_ERROR; 00031 case CURLE_SSL_ENGINE_SETFAILED: 00032 return ErrorCode::GENERIC_SSL_ERROR; 00033 case CURLE_SEND_ERROR: 00034 return ErrorCode::NETWORK_SEND_FAILURE; 00035 case CURLE_RECV_ERROR: 00036 return ErrorCode::NETWORK_RECEIVE_ERROR; 00037 case CURLE_SSL_CERTPROBLEM: 00038 return ErrorCode::SSL_LOCAL_CERTIFICATE_ERROR; 00039 case CURLE_SSL_CIPHER: 00040 return ErrorCode::GENERIC_SSL_ERROR; 00041 case CURLE_SSL_CACERT: 00042 return ErrorCode::SSL_CACERT_ERROR; 00043 case CURLE_USE_SSL_FAILED: 00044 return ErrorCode::GENERIC_SSL_ERROR; 00045 case CURLE_SSL_ENGINE_INITFAILED: 00046 return ErrorCode::GENERIC_SSL_ERROR; 00047 case CURLE_SSL_CACERT_BADFILE: 00048 return ErrorCode::SSL_CACERT_ERROR; 00049 case CURLE_SSL_SHUTDOWN_FAILED: 00050 return ErrorCode::GENERIC_SSL_ERROR; 00051 case CURLE_SSL_CRL_BADFILE: 00052 return ErrorCode::SSL_CACERT_ERROR; 00053 case CURLE_SSL_ISSUER_ERROR: 00054 return ErrorCode::SSL_CACERT_ERROR; 00055 case CURLE_TOO_MANY_REDIRECTS: 00056 return ErrorCode::OK; 00057 default: 00058 return ErrorCode::INTERNAL_ERROR; 00059 } 00060 } 00061 00062 } // namespace cpr