309adfb9738f4391de4e2f9b4922ac497b792c95
[yaffs-website] / vendor / jcalderonzumba / gastonjs / src / Exception / JavascriptError.php
1 <?php
2
3 namespace Zumba\GastonJS\Exception;
4
5
6 /**
7  * Class JavascriptError
8  * @package Zumba\GastonJS\Exception
9  */
10 class JavascriptError extends ClientError {
11
12   /**
13    * @param array $response
14    */
15   public function __construct($response) {
16     parent::__construct($response);
17     $this->message = $this->message();
18   }
19
20   /**
21    * Get the javascript errors found during the use of the phantomjs
22    * @return array
23    */
24   public function javascriptErrors() {
25     $jsErrors = array();
26     $errors = $this->response["error"]["args"][0];
27     foreach ($errors as $error) {
28       $jsErrors[] = new JSErrorItem($error["message"], $error["stack"]);
29     }
30     return $jsErrors;
31   }
32
33   /**
34    * Returns the javascript errors found
35    * @return string
36    */
37   public function message() {
38     $error = "One or more errors were raised in the Javascript code on the page.
39             If you don't care about these errors, you can ignore them by
40             setting js_errors: false in your Poltergeist configuration (see documentation for details).";
41     //TODO: add javascript errors
42     $jsErrors = $this->javascriptErrors();
43     foreach($jsErrors as $jsError){
44       $error = "$error\n$jsError";
45     }
46     return $error;
47   }
48 }