Skip to content

Commit

Permalink
Report json errors to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
LegNeato committed Apr 11, 2012
1 parent 7b1b8a0 commit 8912fa1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
31 changes: 19 additions & 12 deletions BugzillaOutput.class.php
Expand Up @@ -6,38 +6,45 @@ abstract class BugzillaOutput {
public $cache;

public function __construct($config, $options, $title='') {
$this->title = $title;
$this->config = $config;
$this->title = $title;
$this->config = $config;
$this->error = FALSE;
$this->response = new stdClass();

// Make our query and possibly fetch the data
$this->query = BugzillaQuery::create($config['type'], $options, $title);


//error_log($this->query);
//error_log($this->query->id());
//error_log(print_r($this->query->data, true));

// Bubble up any query errors
if( $this->query->error ) {
$this->error = $this->query->error;
}
}

protected function _render_error() {
$what = (!empty($this->error)) ? $this->error : 'Unknown Error';
return "<div class='bugzilla error'>Bugzilla Error: $what</div>";
protected function _render_error($error) {
$this->template = dirname(__FILE__) . '/templates/error.tpl';
ob_start(); // Start output buffering.
require($this->template);
return ob_get_clean();
}

public function render() {

// Get our template path
$this->template = dirname(__FILE__) . '/templates/' .
$this->config['type'] . '/' .
$this->config['display'] . '.tpl';

//error_log($this->template);

// Make sure a template is there
if( !file_exists($this->template) ) {
$this->error = 'Invalid type and display combination';
}

// If there are any errors (either from the template path above or
// elsewhere) output them
if( $this->error ) {
return $this->_render_error($this->error);
}

$this->_setup_template_data();

$response = $this->response;
Expand Down
7 changes: 7 additions & 0 deletions templates/error.tpl
@@ -0,0 +1,7 @@
<!-- Structure mimics existing mediawiki error boxes -->
<div class="bugzilla errorbox">
<h2>Bugzilla query error</h2>
<p>
<?php echo $error; ?>
</p>
</div>

0 comments on commit 8912fa1

Please sign in to comment.