composer package updates
[openemr.git] / vendor / doctrine / couchdb / lib / Doctrine / CouchDB / HTTP / HTTPException.php
blob74e0f6f043c8e6bcac89cbaeabea47a1124b4ee6
1 <?php
3 namespace Doctrine\CouchDB\HTTP;
5 /**
6 * Base exception class for package Doctrine\ODM\CouchDB\HTTP
8 * @license http://www.opensource.org/licenses/mit-license.php MIT
9 * @link www.doctrine-project.com
10 * @since 1.0
11 * @author Kore Nordmann <kore@arbitracker.org>
13 class HTTPException extends \Doctrine\CouchDB\CouchDBException
15 /**
16 * @param string $ip
17 * @param integer $port
18 * @param string $errstr
19 * @param integer $errno
20 * @return \Doctrine\CouchDB\HTTP\HTTPException
22 public static function connectionFailure( $ip, $port, $errstr, $errno )
24 return new self( sprintf(
25 "Could not connect to server at %s:%d: '%d: %s'",
26 $ip,
27 $port,
28 $errno,
29 $errstr
30 ), $errno );
33 /**
34 * @param string $ip
35 * @param integer $port
36 * @param string $errstr
37 * @param integer $errno
38 * @return \Doctrine\CouchDB\HTTP\HTTPException
40 public static function readFailure( $ip, $port, $errstr, $errno )
42 return new static( sprintf(
43 "Could read from server at %s:%d: '%d: %s'",
44 $ip,
45 $port,
46 $errno,
47 $errstr
48 ), $errno );
51 /**
52 * @param string $path
53 * @param Response $response
54 * @return \Doctrine\CouchDB\HTTP\HTTPException
56 public static function fromResponse( $path, Response $response )
58 $response = self::fixCloudantBulkCustomError($response);
60 if (!isset($response->body['error'])) {
61 $response->body['error'] = '';
64 return new self(
65 "HTTP Error with status " . $response->status . " occoured while "
66 . "requesting " . $path . ". Error: " . $response->body['error']
67 . " " . $response->body['reason'],
68 $response->status );
71 private static function fixCloudantBulkCustomError($response)
73 if (isset($response->body[0]['error']) && isset($response->body[0]['reason'])) {
74 $response->body['error'] = $response->body[0]['error'];
75 $response->body['reason'] = $response->body[0]['reason'];
78 return $response;