@@ -1031,7 +1031,7 @@ public function oauth_authenticate($force_login = NULL, $screen_name = NULL, $ty
1031
1031
throw new \Exception ('To get the ' . $ type . ' URL, use the correct third parameter, or omit it. ' );
1032
1032
}
1033
1033
if ($ this ->_oauth_token === null ) {
1034
- throw new \ Exception ('To get the ' . $ type . ' URL, the OAuth token must be set. ' );
1034
+ throw new CodeBirdCredentialsException ('To get the ' . $ type . ' URL, the OAuth token must be set. ' );
1035
1035
}
1036
1036
$ url = self ::$ _endpoints ['oauth ' ] . 'oauth/ ' . $ type . '?oauth_token= ' . $ this ->_url ($ this ->_oauth_token );
1037
1037
if ($ force_login ) {
@@ -1226,7 +1226,7 @@ private function _getProxyData($name)
1226
1226
protected function _oauth2TokenCurl ()
1227
1227
{
1228
1228
if (self ::$ _consumer_key<
10000
/span> === null ) {
1229
- throw new \ Exception ('To obtain a bearer token, the consumer key must be set. ' );
1229
+ throw new CodeBirdCredentialsException ('To obtain a bearer token, the consumer key must be set. ' );
1230
1230
}
1231
1231
$ post_fields = [
1232
1232
'grant_type ' => 'client_credentials '
@@ -1244,7 +1244,7 @@ protected function _oauth2TokenCurl()
1244
1244
1245
1245
// catch request errors
1246
1246
if ($ result === false ) {
1247
- throw new \ Exception ('Request error for bearer token: ' . $ this ->_curl_error ($ connection ));
1247
+ throw new CodeBirdAuthException ('Request error for bearer token: ' . $ this ->_curl_error ($ connection ));
1248
1248
}
1249
1249
1250
1250
// certificate validation results
@@ -1266,14 +1266,14 @@ protected function _oauth2TokenCurl()
1266
1266
protected function _oauth2TokenNoCurl ()
1267
1267
{
1268
1268
if (self ::$ _consumer_key == null ) {
1269
- throw new \ Exception ('To obtain a bearer token, the consumer key must be set. ' );
1269
+ throw new CodeBirdCredentialsException ('To obtain a bearer token, the consumer key must be set. ' );
1270
1270
}
1271
1271
1272
1272
$ url = self ::$ _endpoints ['oauth ' ] . 'oauth2/token ' ;
1273
1273
$ hostname = parse_url ($ url , PHP_URL_HOST );
1274
1274
1275
1275
if ($ hostname === false ) {
1276
- throw new \ Exception ('Incorrect API endpoint host. ' );
1276
+ throw new CodeBirdEndpointException ('Incorrect API endpoint host. ' );
1277
1277
}
1278
1278
1279
1279
$ contextOptions = [
@@ -1465,7 +1465,7 @@ protected function _url($data)
1465
1465
protected function _sha1 ($ data )
1466
1466
{
1467
1467
if (self ::$ _consumer_secret === null ) {
1468
- throw new \ Exception ('To generate a hash, the consumer secret must be set. ' );
1468
+ throw new CodeBirdCredentialsException ('To generate a hash, the consumer secret must be set. ' );
1469
1469
}
1470
1470
if (!function_exists ('hash_hmac ' )) {
1471
1471
throw new \Exception ('To generate a hash, the PHP hash extension must be available. ' );
@@ -1540,7 +1540,7 @@ protected function _getSignature($httpmethod, $method, $base_params)
1540
1540
protected function _sign ($ httpmethod , $ method , $ params = [])
1541
1541
{
1542
1542
if (self ::$ _consumer_key === null ) {
1543
- throw new \ Exception ('To generate a signature, the consumer key must be set. ' );
1543
+ throw new CodeBirdCredentialsException ('To generate a signature, the consumer key must be set. ' );
1544
1544
}
1545
1545
$ sign_base_params = array_map (
1546
1546
[$ this , '_url ' ],
@@ -1743,7 +1743,7 @@ protected function _getMultipartRequestFromParams($method_template, $border, $pa
1743
1743
foreach ($ params as $ key => $ value ) {
1744
1744
// is it an array?
1745
1745
if (is_array ($ value )) {
1746
- throw new \ Exception ('Using URL-encoded parameters is not supported for uploading media. ' );
1746
+ throw new CodeBirdMediaException ('Using URL-encoded parameters is not supported for uploading media. ' );
1747
1747
}
1748
1748
$ request .=
1749
1749
'-- ' . $ border . "\r\n"
@@ -1874,7 +1874,7 @@ protected function _fetchRemoteFile($url)
1874
1874
) {
1875
1875
return $ result ;
1876
1876
}
1877
- throw new \ Exception ('Downloading a remote media file failed. ' );
1877
+ throw new CodeBirdMediaException ('Downloading a remote media file failed. ' );
1878
1878
return
8000
false ;
1879
1879
}
1880
1880
// no cURL
@@ -1894,7 +1894,7 @@ protected function _fetchRemoteFile($url)
1894
1894
) {
1895
1895
return $ result ;
1896
1896
}
1897
- throw new \ Exception ('Downloading a remote media file failed. ' );
1897
+ throw new CodeBirdMediaException ('Downloading a remote media file failed. ' );
1898
1898
return false ;
1899
1899
}
1900
1900
@@ -2025,7 +2025,7 @@ protected function _callApi($httpmethod, $method, $method_template, $params = []
2025
2025
&& $ this ->_oauth_token === null
2026
2026
&& substr ($ method , 0 , 5 ) !== 'oauth '
2027
2027
) {
2028
- throw new \ Exception ('To call this API, the OAuth access token must be set. ' );
2028
+ throw new CodeBirdCredentialsException ('To call this API, the OAuth access token must be set. ' );
2029
2029
}
2030
2030
// use separate API access for streaming API
2031
2031
if ($ this ->_detectStreaming ($ method ) !== false ) {
@@ -2124,7 +2124,7 @@ protected function _callApiNoCurl(
2124
2124
2125
2125
$ hostname = parse_url ($ url , PHP_URL_HOST );
2126
2126
if ($ hostname === false ) {
2127
- throw new \ Exception ('Incorrect API endpoint host. ' );
2127
+ throw new CodeBirdEndpointException ('Incorrect API endpoint host. ' );
2128
2128
}
2129
2129
2130
2130
$ request_headers [] = 'Authorization: ' . $ authorization ;
@@ -2296,7 +2296,7 @@ protected function _getBearerAuthorization()
2296
2296
if (self ::$ _consumer_key === null
2297
2297
&& self ::$ _bearer_token === null
2298
2298
) {
2299
- throw new \ Exception ('To make an app-only auth API request, consumer key or bearer token must be set. ' );
2299
+ throw new CodeBirdCredentialsException ('To make an app-only auth API request, consumer key or bearer token must be set. ' );
2300
2300
}
2301
2301
// automatically fetch bearer token, if necessary
2302
2302
if (self ::$ _bearer_token === null ) {
@@ -2373,7 +2373,7 @@ protected function _callApiStreaming(
2373
2373
$ path = parse_url ($ url , PHP_URL_PATH );
2374
2374
$ query = parse_url ($ url , PHP_URL_QUERY );
2375
2375
if ($ hostname === false ) {
2376
- throw new \ Exception ('Incorrect API endpoint host. ' );
2376
+ throw new CodeBirdEndpointException ('Incorrect API endpoint host. ' );
2377
2377
}
2378
2378
2379
2379
$ request_headers [] = 'Authorization: ' . $ authorization ;
@@ -2635,4 +2635,36 @@ protected function _parseApiReply($reply)
2635
2635
}
2636
2636
return $ parsed ;
2637
2637
}
2638
+
2639
+ }
2640
+
2641
+ /**
2642
+ * Catch errors when authtoken is expired
2643
+ */
2644
+ class CodeBirdAuthException extends \Exception {
2645
+
2646
+ }
2647
+
2648
+
2649
+ /**
2650
+ * Catch error when credentials are not set correclty
2651
+ */
2652
+ class CodeBirdCredentialsException extends \Exception {
2653
+
2638
2654
}
2655
+
2656
+ /**
2657
+ * Catch errors r elated to bad endpoi ts
2658
+ */
2659
+ class CodeBirdEndpointException extends \Exception {
2660
+
2661
+ }
2662
+
2663
+ /*
2664
+ * Catch errors relatedto media
2665
+ */
2666
+
2667
+ class CodeBirdMediaException extends \Exception {
2668
+
2669
+ }
2670
+
0 commit comments