1#include "cpr/error.h"
2
3#include <curl/curl.h>
4
5namespace cpr {
6ErrorCode Error::getErrorCodeForCurlError(std::int32_t curl_code) {
7 switch (curl_code) {
8 case CURLE_OK:
9 return ErrorCode::OK;
10 case CURLE_UNSUPPORTED_PROTOCOL:
11 return ErrorCode::UNSUPPORTED_PROTOCOL;
12 case CURLE_URL_MALFORMAT:
13 return ErrorCode::INVALID_URL_FORMAT;
14 case CURLE_COULDNT_RESOLVE_PROXY:
15 return ErrorCode::PROXY_RESOLUTION_FAILURE;
16 case CURLE_COULDNT_RESOLVE_HOST:
17 return ErrorCode::HOST_RESOLUTION_FAILURE;
18 case CURLE_COULDNT_CONNECT:
19 return ErrorCode::CONNECTION_FAILURE;
20 case CURLE_OPERATION_TIMEDOUT:
21 return ErrorCode::OPERATION_TIMEDOUT;
22 case CURLE_SSL_CONNECT_ERROR:
23 return ErrorCode::SSL_CONNECT_ERROR;
24#if LIBCURL_VERSION_NUM < 0x073e00
25 case CURLE_PEER_FAILED_VERIFICATION:
26 return ErrorCode::SSL_REMOTE_CERTIFICATE_ERROR;
27#endif
28 case CURLE_ABORTED_BY_CALLBACK:
29 case CURLE_WRITE_ERROR:
30 return ErrorCode::REQUEST_CANCELLED;
31 case CURLE_GOT_NOTHING:
32 return ErrorCode::EMPTY_RESPONSE;
33 case CURLE_SSL_ENGINE_NOTFOUND:
34 case CURLE_SSL_ENGINE_SETFAILED:
35 return ErrorCode::GENERIC_SSL_ERROR;
36 case CURLE_SEND_ERROR:
37 return ErrorCode::NETWORK_SEND_FAILURE;
38 case CURLE_RECV_ERROR:
39 return ErrorCode::NETWORK_RECEIVE_ERROR;
40 case CURLE_SSL_CERTPROBLEM:
41 return ErrorCode::SSL_LOCAL_CERTIFICATE_ERROR;
42 case CURLE_SSL_CIPHER:
43 return ErrorCode::GENERIC_SSL_ERROR;
44#if LIBCURL_VERSION_NUM >= 0x073e00
45 case CURLE_PEER_FAILED_VERIFICATION:
46 return ErrorCode::SSL_REMOTE_CERTIFICATE_ERROR;
47#else
48 case CURLE_SSL_CACERT:
49 return ErrorCode::SSL_CACERT_ERROR;
50#endif
51 case CURLE_USE_SSL_FAILED:
52 case CURLE_SSL_ENGINE_INITFAILED:
53 return ErrorCode::GENERIC_SSL_ERROR;
54 case CURLE_SSL_CACERT_BADFILE:
55 return ErrorCode::SSL_CACERT_ERROR;
56 case CURLE_SSL_SHUTDOWN_FAILED:
57 return ErrorCode::GENERIC_SSL_ERROR;
58 case CURLE_SSL_CRL_BADFILE:
59 case CURLE_SSL_ISSUER_ERROR:
60 return ErrorCode::SSL_CACERT_ERROR;
61 case CURLE_TOO_MANY_REDIRECTS:
62 return ErrorCode::TOO_MANY_REDIRECTS;
63 default:
64 return ErrorCode::INTERNAL_ERROR;
65 }
66}
67
68} // namespace cpr
69