forked from alchemy-fr/Phlickr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Exception.php
124 lines (113 loc) · 3.06 KB
/
Exception.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Phlickr makes use of PHP5 exceptions to simplify the detection of and
* differentiation programming and connection errors.
*
* @version $Id$
* @author Andrew Morton <[email protected]>
* @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General
* Public License, Version 2.1
* @package Phlickr
* @todo Split this into separate files.
*/
/**
* Exception base class thrown when there is no more specific exception.
* Callers should use this as their final catch when calling various Phlickr
* functions.
*
* @package Phlickr
* @author Andrew Morton <[email protected]>
*/
class Phlickr_Exception extends Exception {
}
/**
* Exception thrown when there is a problem connecting to the service.
*
* @package Phlickr
* @author Andrew Morton <[email protected]>
*/
class Phlickr_ConnectionException extends Phlickr_Exception {
/**
* The URL that was being requested when the problem occured.
*
* @var string
*/
protected $_url;
/**
* Constructor
*
* @param string $message Error message
* @param integer $code Error code
* @param string $url URL accessed during failure
*/
public function __construct($message = null, $code = null, $url = null) {
parent::__construct($message, $code);
$this->_url = (string) $url;
}
public function __toString() {
$s = "exception '" . __CLASS__ . "' [{$this->code}]: {$this->message}\n";
if (isset($this->_url)) {
$s .= "URL: {$this->_url}\n";
}
$s .= "Stack trace:\n" . $this->getTraceAsString();
return $s;
}
/**
* Return the URL associated with the connection failure.
*
* @return string
*/
public function getUrl() {
return $this->_url;
}
}
/**
* Exception (optionally) thrown when an API method call fails.
*
* You can determine if this exception should be thrown by calling
* Phlickr_Request's setExceptionThrownOnFailure() method.
*
* @package Phlickr
* @author Andrew Morton <[email protected]>
*/
class Phlickr_MethodFailureException extends Phlickr_Exception {
}
/**
* Exception thrown when XML cannot be parsed.
*
* @package Phlickr
* @author Andrew Morton <[email protected]>
*/
class Phlickr_XmlParseException extends Phlickr_Exception {
/**
*
* @var string
*/
protected $_xml;
/**
* Constructor
*
* @param string $message
* @param string $xml
*/
public function __construct($message = null, $xml = null) {
parent::__construct($message);
$this->_xml = (string) $xml;
}
public function __toString() {
$s = "exception '" . __CLASS__ . "' {$this->message}\n";
if (isset($this->_xml)) {
$s .= "XML: '{$this->_xml}'\n";
}
$s .= "Stack trace:\n" . $this->getTraceAsString();
return $s;
}
/**
* Return the un-parseable XML.
*
* @return string
*/
public function getXml() {
return $this->_xml;
}
}