Overview

Namespaces

  • ApiAxle
    • Api
    • Shared
  • ApiAxleTest
    • Api
    • Shared
  • PHP

Classes

  • Config
  • HttpRequest
  • ItemList
  • Utilities

Exceptions

  • ApiException
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: /**
 3:  * ApiAxle (https://github.com/fillup/apiaxle-module)
 4:  *
 5:  * @link      https://github.com/fillup/apiaxle-module for the canonical source repository
 6:  * @license   MIT
 7:  */
 8: namespace ApiAxle\Shared;
 9: 
10: /**
11:  * Custom Exception class to also store API response for further information
12:  * and debugging.
13:  */
14: class ApiException extends \Exception
15: {
16:     /**
17:      * Full API response
18:      * 
19:      * @var string 
20:      */
21:     protected $response;
22:     
23:     /**
24:      * HTTP response code
25:      * 
26:      * @var integer 
27:      */
28:     protected $http_code;
29:     
30:     public function __construct($message, $code, $previous = null, $http_code, $response) {
31:         parent::__construct($message, $code, $previous);
32:         $this->setResponse($response);
33:         $this->http_code = $http_code;
34:     }
35:     
36:     public function setResponse($response)
37:     {
38:         if(is_object($response) || is_array($response)){
39:             $this->response = json_encode($response);
40:         } else {
41:             $this->response = $response;
42:         }
43:     }
44:     
45:     public function getResponse()
46:     {
47:         return $this->response;
48:     }
49:     
50:     public function __toString() {
51:         $error = 'Message: '.$this->getMessage()."\n";
52:         $error .= 'Code: '.$this->getCode().'\n';
53:         $error .= 'Response: '.$this->getResponse();
54:         
55:         return __CLASS__.':\n'.$error;
56:     }
57: }
58: 
fillup/apiaxle API documentation generated by ApiGen 2.8.0