Skip to content

Commit

Permalink
Better handle feedback request response and error logging and make re…
Browse files Browse the repository at this point in the history
…port email comply with 75 chars limit

I switched the args for the url because it is safer from an encoding point of view

Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed May 30, 2021
1 parent 9a0f5d4 commit 3454b13
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/Forwarding/Sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public static function sendFeedback(string $eventId, string $comments, string $u

$data = [
'comments' => $comments,
'email' => 'users+' . $userId . '@phpmyadmin.local',
'email' => 'u+' . $userId . '@r.local',// 75 chars max (fake hostname to pass email validation rule)
'name' => 'phpMyAdmin User',
];
$ch = curl_init(
$sentryConfig['base_url'] . '/api/embed/error-page/?dsn=' . $sentryConfig['dsn_url'] . '&eventId=' . $eventId
$sentryConfig['base_url'] . '/api/embed/error-page/?eventId=' . $eventId . '&dsn=' . $sentryConfig['dsn_url']
);
if ($ch === false) {
throw new Exception('Could not init cURL');
Expand All @@ -123,7 +123,28 @@ public static function sendFeedback(string $eventId, string $comments, string $u
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

curl_exec($ch);
$output = curl_exec($ch);
if (! is_string($output)) {
$error = 'Creating the report feedback failed: ' . json_encode($output);
Log::error($error);

return;
}

$response = json_decode((string) $output, true);
if (! is_array($response)) {
$error = 'Invalid JSON response: ' . json_encode($output);
Log::error($error);

return;
}

if (isset($response['errors'])) {
$error = 'Response has errors: ' . json_encode($response['errors']);
Log::error($error);

return;
}
}

public static function process(Report $report): void
Expand Down

0 comments on commit 3454b13

Please sign in to comment.