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 May 16, 2012
1 parent ab4852f commit d0a1f77
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
28 changes: 17 additions & 11 deletions BugzillaOutput.class.php
Expand Up @@ -8,37 +8,43 @@ abstract class BugzillaOutput {
public function __construct($config, $options, $title='') { public function __construct($config, $options, $title='') {
$this->title = $title; $this->title = $title;
$this->config = $config; $this->config = $config;
$this->error = FALSE;
$this->response = new stdClass(); $this->response = new stdClass();


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



// Bubble up any query errors
//error_log($this->query); if( $this->query->error ) {
//error_log($this->query->id()); $this->error = $this->query->error;
//error_log(print_r($this->query->data, true)); }

} }


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


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


//error_log($this->template);

// Make sure a template is there // Make sure a template is there
if( !file_exists($this->template) ) { if( !file_exists($this->template) ) {
$this->error = 'Invalid type and display combination'; $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(); $this->_setup_template_data();


$response = $this->response; $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 d0a1f77

Please sign in to comment.