| 1 | <?php |
||
| 9 | class CouldNotSendNotification extends Exception |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @param \Psr\Http\Message\ResponseInterface $response |
||
| 13 | * @return static |
||
| 14 | */ |
||
| 15 | 1 | public static function serviceRespondedWithAnHttpError(ResponseInterface $response) |
|
| 16 | { |
||
| 17 | 1 | $message = "Discord responded with an HTTP error: {$response->getStatusCode()}"; |
|
| 18 | |||
| 19 | 1 | if ($error = Arr::get(json_decode($response->getBody(), true), 'message')) { |
|
| 20 | $message .= ": $error"; |
||
| 21 | } |
||
| 22 | |||
| 23 | 1 | return new static($message); |
|
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param array $response |
||
| 28 | * @return static |
||
| 29 | */ |
||
| 30 | 1 | public static function serviceRespondedWithAnApiError(array $response) |
|
| 31 | { |
||
| 32 | 1 | return new static("Discord responded with an API error: {$response['code']}: {$response['message']}"); |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param \Exception $exception |
||
| 37 | * @return static |
||
| 38 | */ |
||
| 39 | 1 | public static function serviceCommunicationError(Exception $exception) |
|
| 43 | } |
||
| 44 |