/** * adds an exception as error to the errors collection * this will end up in response.errors[] * * @note exception meta data (file, line, trace) is only shown when debug mode is on (@see base::$debug) * * @param object $exception extending \Exception * @param string $friendly_message optional, @see jsonapi\error->set_friendly_message() * @param string $about_link optional, @see jsonapi\error->set_about_link() */ public function add_exception($exception, $friendly_message = null, $about_link = null) { $error_message = $exception->getMessage(); $error_status = $exception->getCode(); $new_error = new error($error_message, $friendly_message, $about_link); if ($error_status) { $new_error->set_http_status($error_status); } // meta data if (base::$debug) { $file = $exception->getFile(); if ($file) { $file = str_replace($_SERVER['DOCUMENT_ROOT'] . '/', '', $file); $new_error->add_meta('file', $file); } $line = $exception->getLine(); if ($line) { $new_error->add_meta('line', $line); } $trace = $exception->getTrace(); if ($trace) { foreach ($trace as &$place) { if (!empty($place['file'])) { $place['file'] = str_replace($_SERVER['DOCUMENT_ROOT'] . '/', '', $place['file']); } } $new_error->add_meta('trace', $trace); } } $this->add_error_object($new_error); $previous_exception = $exception->getPrevious(); if ($previous_exception) { $this->add_exception($previous_exception); } }