CouldNotSendNotification::alertIdNotProvided()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace NotificationChannels\Hooks\Exceptions;
4
5
use Exception;
6
use GuzzleHttp\Exception\ClientException;
7
8
class CouldNotSendNotification extends \Exception
9
{
10
    /**
11
     * Thrown when there's a bad request and an error is responded.
12
     *
13
     * @param ClientException $exception
14
     *
15
     * @return static
16
     */
17
    public static function hooksRespondedWithAnError(ClientException $exception)
18
    {
19
        $statusCode = $exception->getResponse()->getStatusCode();
20
        $result = json_decode($exception->getResponse()->getBody());
21
22
        return new static("Hooks API responded with an error `{$statusCode} - {$result->status} : {$result->msg}`");
23
    }
24
25
    /**
26
     * Thrown when there's no api key provided.
27
     *
28
     * @param string $message
29
     *
30
     * @return static
31
     */
32
    public static function hooksApiKeyNotProvided($message)
33
    {
34
        return new static($message);
35
    }
36
37
    /**
38
     * Thrown when we're unable to communicate with Hooks API.
39
     *
40
     * @param \Exception $exception
41
     *
42
     * @return static
43
     */
44
    public static function couldNotCommunicateWithHooks(Exception $exception)
45
    {
46
        return new static('The communication with Hooks API failed. Reason: '.$exception->getMessage());
47
    }
48
49
    public static function alertIdNotProvided()
50
    {
51
        return new static('Alert ID for this notification was not provided.');
52
    }
53
}
54