Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: rldhont <[email protected]>
  • Loading branch information
Gustry and rldhont authored Dec 3, 2024
1 parent d14e21e commit 1c73f74
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lizmap/modules/lizmap/lib/Request/OGCRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,18 @@ protected function constructUrl()
*/
private function formatHttpErrorString($params, $code)
{
$message = '';

$paramsToLog = array('map', 'repository', 'project', 'service', 'request');
foreach ($paramsToLog as $paramName) {
$mainParamsToLog = array('map', 'repository', 'project', 'service', 'request');
$mainParamValues = array();
$otherParamValues = array();
foreach ($mainParamsToLog as $paramName) {
if (array_key_exists($paramName, $params)) {
$message .= strtoupper($paramName)." '".$params[$paramName]."', ";
$mainParamValues[] = '"'.strtoupper($paramName).'"'. ' = ' ."'".$params[$paramName]."'";
} else {
$otherParamValues[] = '"'.strtoupper($paramName).'"'. ' = ' ."'".$params[$paramName]."'";
}
}

$message = rtrim($message, ', ');
$message = implode(' & ', $mainParamvalues) .'\n'. implode(' & ', $otherParamvalues);

return 'HTTP code '.$code.' on '.$message;
}
Expand All @@ -225,15 +227,15 @@ protected function logRequestIfError($code)
// The master error with MAP parameter
// This user must have an access to QGIS Server logs
$params = $this->parameters();
\jLog::log($message.' Check logs on QGIS Server. '.$this->formatHttpErrorString($params, $code).' : '.json_encode($params), 'error');
\jLog::log($message.' Check logs on QGIS Server. '.$this->formatHttpErrorString($params, $code), 'error');

// The admin error without the MAP parameter
// but replaced by REPOSITORY and PROJECT parameters
// This user might not have an access to QGIS Server logs
unset($params['map']);
$params['repository'] = $this->project->getRepository()->getKey();
$params['project'] = $this->project->getKey();
\jLog::log($message.' '.$this->formatHttpErrorString($params, $code).' : '.json_encode($params), 'lizmapadmin');
\jLog::log($message.' '.$this->formatHttpErrorString($params, $code), 'lizmapadmin');
}

/**
Expand Down

0 comments on commit 1c73f74

Please sign in to comment.