-
Notifications
You must be signed in to change notification settings - Fork 12
/
CustomException.php
49 lines (44 loc) · 1.36 KB
/
CustomException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Google Natural Language API Exception
*
* @category Exception
* @package GoogleNaturalLanguagePhp
* @author Darryn Ten <[email protected]>
* @license MIT <https://github.com/darrynten/google-natural-language-php/LICENSE>
* @link https://github.com/darrynten/google-natural-language-php
*/
namespace DarrynTen\GoogleNaturalLanguagePhp;
use \Exception;
/**
* Custom exception for GoogleNaturalLanguage Client
*
* @package GoogleNaturalLanguagePhp
*/
class CustomException extends Exception
{
/**
* @inheritdoc
*
* @param string $message The message to throw
* @param integer $code The error code to throw
* @param Exception $previous The previous exception
*/
public function __construct($message = "", $code = 0, Exception $previous = null)
{
// Construct message from JSON if required.
if (preg_match('/^[\[\{]\"/', $message)) {
$messageObject = json_decode($message);
$message = sprintf(
'%s: %s - %s',
$messageObject->status,
$messageObject->title,
$messageObject->detail
);
if (!empty($messageObject->errors)) {
$message .= ' ' . serialize($messageObject->errors);
}
}
parent::__construct($message, $code, $previous);
}
}