Skip to content

Commit

Permalink
Fix how to log HTTP request having an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry authored and github-actions[bot] committed Dec 3, 2024
1 parent 134fe35 commit e6b1ea8
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions lizmap/modules/lizmap/lib/Request/OGCRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,44 @@ protected function constructUrl()
/**
* Generate a string to identify the target of the HTTP request.
*
* @param array $params The list of HTTP params
* @param int $code The HTTP code of the request
* @param array $parameters The list of HTTP parameters in the query
* @param int $code The HTTP code of the request
*
* @return string The string to identify the HTTP request, with main OGC parameters first such as MAP, SERVICE...
*/
private function formatHttpErrorString($params, $code)
private function formatHttpErrorString($parameters, $code)
{
// Clone parameters array to perform unset without modify it
$params = array_merge(array(), $parameters);

// Ordered list of params to fetch first
$mainParamsToLog = array('map', 'repository', 'project', 'service', 'request');
$mainParamValues = array();
$otherParamValues = array();

$output = array();
foreach ($mainParamsToLog as $paramName) {
if (array_key_exists($paramName, $params)) {
$mainParamValues[] = '"'.strtoupper($paramName).'"'. ' = ' ."'".$params[$paramName]."'";
} else {
$otherParamValues[] = '"'.strtoupper($paramName).'"'. ' = ' ."'".$params[$paramName]."'";
$output[] = '"'.strtoupper($paramName).'" = '."'".$params[$paramName]."'";
unset($params[$paramName]);
}
}

$message = implode(' & ', $mainParamvalues) .'\n'. implode(' & ', $otherParamvalues);
// First implode with main parameters
$message = implode(' & ', $output);

if ($params) {
// Ideally, we want two lines, one with main parameters, the second one with secondary parameters
// It does not work in jLog
// $message .= '\n';
$message .= ' & ';
}

// For remaining parameters in the array, which are not in the main list
$output = array();
foreach ($params as $key => $value) {
$output[] = '"'.strtoupper($key).'" = '."'".$value."'";
}

$message .= implode(' & ', $output);

return 'HTTP code '.$code.' on '.$message;
}
Expand Down

0 comments on commit e6b1ea8

Please sign in to comment.