Skip to content

Commit

Permalink
Increased insight and logging of sourceforge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
m0hamed committed Mar 5, 2014
1 parent 7174a00 commit 1735c03
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
9 changes: 9 additions & 0 deletions app/Config/bootstrap.php
Expand Up @@ -98,17 +98,26 @@
* Configures default file logging options
*/
App::uses('CakeLog', 'Log');

CakeLog::config('debug', array(
'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));

CakeLog::config('error', array(
'engine' => 'FileLog',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));

CakeLog::config('sourceforge', array(
'engine' => 'FileLog',
'types' => array('custom'),
'scopes' => array('sourceforge'),
'file' => 'sourceforge',
));

/**
* Loads plugins
*/
Expand Down
36 changes: 25 additions & 11 deletions app/Controller/SourceForgeController.php
Expand Up @@ -84,8 +84,12 @@ public function create_ticket($reportId) {
} else {
//fail
$response->body = json_decode($response->body, true);
$this->Session->setFlash($this->_getValidationErrors(
$response->body['errors']), "default",
CakeLog::write('custom', 'Submission for sourceforge ticket may have failed.',
'sourceforge');
CakeLog::write('custom', 'Response dump:', 'sourceforge');
CakeLog::write('custom', print_r($response["raw"], true), 'sourceforge');
$this->Session->setFlash($this->_getErrors(
$response->body), "default",
array("class" => "alert alert-error"));
}
}
Expand All @@ -106,17 +110,27 @@ protected function _getTicketData($reportId) {
return $data;
}

protected function _getValidationErrors($errors) {
$errorString = "There were some problems with the ticket submission:";
$errorString .= '<ul>';

foreach ($errors['ticket_form'] as $field => $message) {
$errorString .= "<li>";
$errorString .= "$field: $message";
$errorString .= "</li>";
protected function _getErrors($body) {
$errorString = "There were some problems with the ticket submission."
." Returned status is (" . $body["status"] . ")";

$errors = $body["errors"];
if ($body["status"] === "Validation Error") {
$errorString .= '<ul>';
foreach ($errors['ticket_form'] as $field => $message) {
$errorString .= "<li>";
$errorString .= "$field: $message";
$errorString .= "</li>";
}
$errorString .= '</ul>';
} else {
$errorString .= "<br/> Here is the dump for the errors field provided by"
. " sourceforge: <br/>"
. "<pre>"
. print_r($errors, true)
. "</pre>";
}

$errorString .= '</ul>';
return $errorString;
}

Expand Down

0 comments on commit 1735c03

Please sign in to comment.