Updating Media dependent modules to versions compatible with core Media.
[yaffs-website] / web / modules / contrib / media_entity_twitter / src / Exception / TwitterApiException.php
1 <?php
2
3 namespace Drupal\media_entity_twitter\Exception;
4
5 /**
6  * Exception thrown when Twitter's API returns errors in a response.
7  */
8 class TwitterApiException extends \Exception {
9
10   /**
11    * TwitterApiException constructor.
12    *
13    * @param array $errors
14    *   The errors returned from Twitter's API. Each error contains 'message'
15    *   and 'code' elements.
16    * @param int $code
17    *   (optional) The general error code for the exception.
18    * @param \Exception|null $previous
19    *   (optional) The previous exception.
20    *
21    * @see https://dev.twitter.com/overview/api/response-codes
22    */
23   public function __construct(array $errors, $code = 0, \Exception $previous = NULL) {
24     $errors = array_map(
25       function (array $error) {
26         return sprintf('[%d] %s', $error['code'], $error['message']);
27       },
28       $errors
29     );
30
31     array_unshift($errors, 'Twitter API returned error(s):');
32     $errors = implode("\n", $errors);
33
34     parent::__construct($errors, $code, $previous);
35   }
36
37 }