1<?php
2
3final class HTTPFutureCURLResponseStatus extends HTTPFutureResponseStatus {
4
5  protected function getErrorCodeType($code) {
6    return 'cURL';
7  }
8
9  public function isError() {
10    return true;
11  }
12
13  public function isTimeout() {
14    // NOTE: The PHP error constant for this is nonsensical (this is not an
15    // error):
16    //
17    //    PHP: CURLE_OPERATION_TIMEOUTED
18    //   cURL: CURLE_OPERATION_TIMEDOUT
19
20    return ($this->getStatusCode() == CURLE_OPERATION_TIMEOUTED);
21  }
22
23  protected function getErrorCodeDescription($code) {
24    $constants = get_defined_constants();
25
26    $constant_name = null;
27    foreach ($constants as $constant => $value) {
28      if ($value == $code && preg_match('/^CURLE_/', $constant)) {
29        $constant_name = '<'.$constant.'> ';
30        break;
31      }
32    }
33
34    $map = array(
35      CURLE_COULDNT_RESOLVE_HOST => pht(
36        'There was an error resolving the server hostname. Check that you are '.
37        'connected to the internet and that DNS is correctly configured. (Did '.
38        'you add the domain to `%s` on some other machine, but not this one?)',
39        '/etc/hosts'),
40
41      CURLE_SSL_CACERT => pht(
42        'There was an error verifying the SSL Certificate Authority while '.
43        'negotiating the SSL connection. This usually indicates that you are '.
44        'using a self-signed certificate but have not added your CA to the '.
45        'CA bundle. See instructions in "%s".',
46        'arcanist/resources/ssl/README'),
47
48      // Apparently there's no error constant for this? In cURL it's
49      // CURLE_SSL_CACERT_BADFILE but there's no corresponding constant in
50      // PHP.
51      77 => pht(
52        'The SSL CA Bundles that we tried to use could not be read or are '.
53        'not formatted correctly.'),
54
55      CURLE_SSL_CONNECT_ERROR => pht(
56        'There was an error negotiating the SSL connection. This usually '.
57        'indicates that the remote host has a bad SSL certificate, or your '.
58        'local host has some sort of SSL misconfiguration which prevents it '.
59        'from accepting the CA. If you are using a self-signed certificate, '.
60        'see instructions in "%s".',
61        'arcanist/resources/ssl/README'),
62
63      CURLE_OPERATION_TIMEOUTED => pht(
64        'The request took too long to complete.'),
65
66      CURLE_SSL_PEER_CERTIFICATE => pht(
67        'There was an error verifying the SSL connection. This usually '.
68        'indicates that the remote host has an SSL certificate for a '.
69        'different domain name than you are connecting with. Make sure the '.
70        'certificate you have installed is signed for the correct domain.'),
71    );
72
73    $default_message = pht(
74      'The cURL library raised an error while making a request. You may be '.
75      'able to find more information about this error (error code: %d) '.
76      'on the cURL site: %s',
77      $code,
78      'http://curl.haxx.se/libcurl/c/libcurl-errors.html#'.
79      preg_replace('/[^A-Z]/', '', $constant_name));
80
81    $detailed_message = idx($map, $code, $default_message);
82
83    return $constant_name.$detailed_message;
84  }
85
86}
87