|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright (C) 2013-2016 Mailgun |
|
5
|
|
|
* |
|
6
|
|
|
* This software may be modified and distributed under the terms |
|
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Mailgun\Exception; |
|
11
|
|
|
|
|
12
|
|
|
use Mailgun\Exception; |
|
13
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author Tobias Nyholm <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
final class HttpClientException extends \RuntimeException implements Exception |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var ResponseInterface|null |
|
22
|
|
|
*/ |
|
23
|
|
|
private $response; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $message |
|
27
|
|
|
* @param int $code |
|
28
|
|
|
* @param ResponseInterface|null $response |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct($message, $code, ResponseInterface $response = null) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct($message, $code); |
|
33
|
|
|
$this->response = $response; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public static function badRequest(ResponseInterface $response = null) |
|
37
|
|
|
{ |
|
38
|
|
|
return new self('The parameters passed to the API were invalid. Check your inputs!', 400, $response); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public static function unauthorized(ResponseInterface $response = null) |
|
42
|
|
|
{ |
|
43
|
|
|
return new self('Your credentials are incorrect.', 401, $response); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function requestFailed(ResponseInterface $response = null) |
|
47
|
|
|
{ |
|
48
|
|
|
return new self('Parameters were valid but request failed. Try again.', 402, $response); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function notFound(ResponseInterface $response = null) |
|
52
|
|
|
{ |
|
53
|
|
|
return new self('The endpoint you tried to access does not exist. Check your URL.', 404, $response); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return ResponseInterface |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getResponse() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->response; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|