@@ -1045,7 +1045,7 @@ public function oauth_authenticate($force_login = NULL, $screen_name = NULL, $ty
1045
1045
throw new \Exception ('To get the ' . $ type . ' URL, use the correct third parameter, or omit it. ' );
1046
1046
}
1047
1047
if ($ this ->_oauth_token === null ) {
1048
- throw new \ Exception ('To get the ' . $ type . ' URL, the OAuth token must be set. ' );
1048
+ throw new CodebirdCredentialsException ('To get the ' . $ type . ' URL, the OAuth token must be set. ' );
1049
1049
}
1050
1050
$ url = self ::$ _endpoints ['oauth ' ] . 'oauth/ ' . $ type . '?oauth_token= ' . $ this ->_url ($ this ->_oauth_token );
1051
1051
if ($ force_login ) {
@@ -1240,7 +1240,7 @@ private function _getProxyData($name)
1240
1240
protected function _oauth2TokenCurl ()
1241
1241
{
1242
1242
if (self ::$ _consumer_key === null ) {
1243
- throw new \ Exception ('To obtain a bearer token, the consumer key must be set. ' );
1243
+ throw new CodebirdCredentialsException ('To obtain a bearer token, the consumer key must be set. ' );
1244
1244
}
1245
1245
$ post_fields = [
1246
1246
'grant_type ' => 'client_credentials '
@@ -1258,7 +1258,7 @@ protected function _oauth2TokenCurl()
1258
1258
1259
1259
// catch request errors
1260
1260
if ($ result === false ) {
1261
- throw new \ Exception ('Request error for bearer token: ' . $ this ->_curl_error ($ connection ));
1261
+ throw new CodebirdAuthException ('Request error for bearer token: ' . $ this ->_curl_error ($ connection ));
1262
1262
}
1263
1263
1264
1264
// certificate validation results
@@ -1280,14 +1280,14 @@ protected function _oauth2TokenCurl()
1280
1280
protected function _oauth2TokenNoCurl ()
1281
1281
{
1282
1282
if (self ::$ _consumer_key == null ) {
1283
- throw new \ Exception ('To obtain a bearer token, the consumer key must be set. ' );
1283
+ throw new CodebirdCredentialsException ('To obtain a bearer token, the consumer key must be set. ' );
1284
1284
}
1285
1285
1286
1286
$ url = self ::$ _endpoints ['oauth ' ] . 'oauth2/token ' ;
1287
1287
$ hostname = parse_url ($ url , PHP_URL_HOST );
1288
1288
1289
1289
if ($ hostname === false ) {
1290
- throw new \ Exception ('Incorrect API endpoint host. ' );
1290
+ throw new CodebirdEndpointException ('Incorrect API endpoint host. ' );
1291
1291
}
1292
1292
1293
1293
$ contextOptions = [
@@ -1479,7 +1479,7 @@ protected function _url($data)
1479
1479
protected function _sha1 ($ data )
1480
1480
{
1481
1481
if (self ::$ _consumer_secret === null ) {
1482
- throw new \ Exception ('To generate a hash, the consumer secret must be set. ' );
1482
+ throw new CodebirdCredentialsException ('To generate a hash, the consumer secret must be set. ' );
1483
1483
}
1484
1484
if (!function_exists ('hash_hmac ' )) {
1485
1485
throw new \Exception ('To generate a hash, the PHP hash extension must be available. ' );
@@ -1554,7 +1554,7 @@ protected function _getSignature($httpmethod, $method, $base_params)
1554
1554
protected function _sign ($ httpmethod , $ method , $ params = [])
1555
1555
{
1556
1556
if (self ::$ _consumer_key === null ) {
1557
- throw new \ Exception ('To generate a signature, the consumer key must be set. ' );
1557
+ throw new CodebirdCredentialsException ('To generate a signature, the consumer key must be set. ' );
1558
1558
}
1559
1559
$ sign_base_params = array_map (
1560
1560
[$ this , '_url ' ],
@@ -1757,7 +1757,7 @@ protected function _getMultipartRequestFromParams($method_template, $border, $pa
1757
1757
foreach ($ params as $ key => $ value ) {
1758
1758
// is it an array?
1759
1759
if (is_array ($ value )) {
1760
- throw new \ Exception ('Using URL-encoded parameters is not supported for uploading media. ' );
1760
+ throw new CodebirdMediaException ('Using URL-encoded parameters is not supported for uploading media. ' );
1761
1761
}
1762
1762
$ request .=
1763
1763
'-- ' . $ border . "\r\n"
@@ -1888,7 +1888,7 @@ protected function _fetchRemoteFile($url)
1888
1888
) {
1889
1889
return $ result ;
1890
1890
}
1891
- throw new \ Exception ('Downloading a remote media file failed. ' );
1891
+ throw new CodebirdMediaException ('Downloading a remote media file failed. ' );
1892
1892
return false ;
1893
1893
}
1894
1894
// no cURL
@@ -1908,7 +1908,7 @@ protected function _fetchRemoteFile($url)
1908
1908
) {
1909
1909
return $ result ;
1910
1910
}
1911
- throw new \ Exception ('Downloading a remote media file failed. ' );
1911
+ throw new CodebirdMediaException ('Downloading a remote media file failed. ' );
1912
1912
return false ;
1913
1913
}
1914
1914
@@ -2039,7 +2039,7 @@ protected function _callApi($httpmethod, $method, $method_template, $params = []
2039
2039
&& $ this ->_oauth_token === null
2040
2040
&& substr ($ method , 0 , 5 ) !== 'oauth '
2041
2041
) {
2042
- throw new \ Exception ('To call this API, the OAuth access token must be set. ' );
2042
+ throw new CodebirdCredentialsException ('To call this API, the OAuth access token must be set. ' );
2043
2043
}
2044
2044
// use separate API access for streaming API
2045
2045
if ($ this ->_detectStreaming ($ method ) !== false ) {
@@ -2138,7 +2138,7 @@ protected function _callApiNoCurl(
2138
2138
2139
2139
$ hostname = parse_url ($ url , PHP_URL_HOST );
2140
2140
if ($ hostname === false ) {
2141
- throw new \ Exception ('Incorrect API endpoint host. ' );
2141
+ throw new CodebirdEndpointException ('Incorrect API endpoint host. ' );
2142
2142
}
2143
2143
2144
2144
$ request_headers [] = 'Authorization: ' . $ authorization ;
@@ -2310,7 +2310,7 @@ protected function _getBearerAuthorization()
2310
2310
if (self ::$ _consumer_key === null
2311
2311
&& self ::$ _bearer_token === null
2312
2312
) {
2313
- throw new \ Exception ('To make an app-only auth API request, consumer key or bearer token must be set. ' );
2313
+ throw new CodebirdCredentialsException ('To make an app-only auth API request, consumer key or bearer token must be set. ' );
2314
2314
}
2315
2315
// automatically fetch bearer token, if necessary
2316
2316
if (self ::$ _bearer_token === null ) {
@@ -2387,7 +2387,7 @@ protected function _callApiStreaming(
2387
2387
$ path = parse_url ($ url , PHP_URL_PATH );
2388
2388
$ query = parse_url ($ url , PHP_URL_QUERY );
2389
2389
if ($ hostname === false ) {
2390
- throw new \ Exception ('Incorrect API endpoint host. ' );
2390
+ throw new CodebirdEndpointException ('Incorrect API endpoint host. ' );
2391
2391
}
2392
2392
2393
2393
$ request_headers [] = 'Authorization: ' . $ authorization ;
@@ -2649,4 +2649,36 @@ protected function _parseApiReply($reply)
2649
2649
}
2650
2650
return $ parsed ;
2651
2651
}
2652
+
2653
+ }
2654
+
2655
+ /**
2656
+ * Catch errors when authtoken is expired
2657
+ */
2658
+ class CodebirdAuthException extends \Exception {
2659
+
2660
+ }
2661
+
2662
+
2663
+ /**
2664
+ * Catch error when credentials are not set correclty
2665
+ */
2666
+ class CodebirdCredentialsException extends \Exception {
2667
+
2652
2668
}
2669
+
2670
+ /**
2671
+ * Catch errors r elated to bad endpoi ts
2672
+ */
2673
+ class CodebirdEndpointException extends \Exception {
2674
+
2675
+ }
2676
+
2677
+ /*
2678
+ * Catch errors relatedto media
2679
+ */
2680
+
2681
+ class CodebirdMediaException extends \Exception {
2682
+
2683
+ }
2684
+
0 commit comments